Someone sent me a CR the other day. And the code went something like this:
function validateInputLanguage(input: InputOptions): void {
// checking input is valid
if (input.language) {
// ....
// we are good
return;
} else {
input.language = defaultLang;
}
}
The code here doesn’t matter that much though. I read the CR, put the following comments:
I would recommend to not mutate passed input, instead of returning the validation result plus reasons in the return value (instead of void).
Then the engineer relied to me this in the Slack:
Hi Mike, I saw your comments. I just follow what the original code patterns, the other places did the same kind of validations as well.
Every time people replied something like this, they basically shut down a door to ask why.
Yes, I understand there could be other places like this, but what if we start asking questions instead of just trying to get the job done?
Come on, we all have things to do, why bother asking so many questions?
Every code change ultimately is an exercise for our brain, or a hidden conversation to the original author. Even though we could still ended up making the same code change, but with these questions in mind will help you making a bigger impact in the long term.