The importance of good code reviews

I believe code reviews to be one of the most important things to improve your level of technical skill and advancing in your professional career. And because of its importance,

9 years ago

Latest Post Deferring decisions in Evolutionary Architecture by Tim Sommer public

I believe code reviews to be one of the most important things to improve your level of technical skill and advancing in your professional career. And because of its importance, I decided to write a quick post about it.

Negative experiences

More often than not, reviewees tend to have negative experiences associated with code reviews.

This can be caused by many things. It could be that the reviewer wanted to assert his superiority and -intentionally or unintentionally- humiliated the reviewee, making each 'mistake' into a personal attack. Maybe the code review was focused on the wrong things, like grammar in commenting sections. Or maybe the review was always focused on the bad things, making the reviewee feel more and more useless and becoming more and more afraid of writing basic code.

How we do code reviews is very important. I've seen cases where the reviewer -with the best intentions- makes a list of all the 'mistakes', sends an email to the entire team, and leaves it at that. This can be really brutal for a junior, who just got publicly humiliated and thrown to the wolves, without a chance to defend or explain him- or herself.

Yet code reviews are one of the best way to learn, advance and better your programming skills. So we should -and can- do bettter!

Why should we review code?

To make my point absolutely clear, there are only a few reasons why we do code reviews.

When should we review code?

I'm a firm believer in formalizing code reviews as a part in your development process. In an ideal world I would do reviews at the end of each sprint, with change sets as small as possible (smaller means easier review!).
You -or your PM ;)- could argue that this will result in higher development costs. Your entire dev-team will be unavailable for the duration of the review. But doing these formal meetings will improve the technical skills of the programmers, which also means the duration of the review will automatically decrease in time. There is absolutely everything to gain and nothing to lose when you take the time to do your reviews correctly!

You could also ask your developers to ask for code reviews within the TFS source control system. This approach puts the responsibility with your programmer though, which may or may not be the best idea.

How should we review code?

Do it in person! Make sure the reviewee has the opportunity to explain him- or herself. Preferably, let the reviewee go over his or her own changeset, explaining the why and what.

Don't criticize but simply show how to do better. Make sure everyone in the room understands why it can be done better, how it can be done better and that everyone is in agreement. Don't humiliate, crack down or be hard in any way. We all make mistakes and we all started from somewhere. Pay very close attention to how your reviewee responds to the feedback and try your best to adjust your communication style to his or her personality. Always treat your coworkers with respect!

Don't only talk about the bad parts of the code. There will be good stuff in there as well. Make sure you emphasize those and give credit when credit is due.

Don't waste time on stuff that can be automated. Code guidelines are important, but you can use multiple code quality tools to enforce them. You shouldn't ignore them completely, but just try to focus more on the critical and important parts; explain them, make them better and be done with them.

The goal

If you are able to do good code reviews there are many things to gain.

Tim Sommer

Published 9 years ago


Leave us your opinion.