Best Practices for Programmers During Code Reviews

code-reviewsteamwork

I am fairly new to code review, but I have been coding for years during my PhD – which doesn't always make you a good programmer!

If the reviewer changes your code and goes through it with you line-by-line, what do you do if you disagree? Sometimes you made choice X and the reviewer changes it to Y, and you had Y in your mind but decided not to do it because of the disadvantages, but the reviewer asserts that those disadvantages are not important. Should you verbalise your disagreement, or just not and listen to them?

Its difficult if you are not good at accepting criticism, and if the reviewer is a more senior person in the organisation. It would not be good to come across as too defensive.

Best Answer

True, coming across as defensive is not helpful; but then - neither is being criticised, so if you feel this is happening you really should vocalise your concerns that the code review is not helping you write better code within the organisation.

The reviewer has a responsibility to review code for real non-compliance and defects, not use it as a means to write your code the way they would have done. This means the review is there to review how you did something, and point out any areas that you made a mistake (something the best of us do) or didn't understand the framework or standards or "historical reasons" some code is written the way it is where you are.

So if there are multiple ways of doing something, there needs to be a good reason why your code is changed to an alternative way, otherwise its simply non-constructive churn that won't help you.

Also, remember that the reviewer isn't perfect either. They may have an idea that Y is the way to do it, and haven't realised that X is better. You should explain the reasons why you did it in way X. The reviewer might agree with you, or he might tell you why Y is a better solution - there may be other factors that you don't know that he does.

In short, reviews are a way to get team members to communicate about their code changes. So talk to the reviewer about it.

IF it helps, talk in an impartial way, as if you were not even the author of the code being reviewed. The code belongs to the company or team after all, and the team will have to maintain it. You just happened to be the guy who wrote it, that's not as important a factor as many believe.

Related Topic