The last couple of weeks I have been actively involved in writing a code review for the project I’m currently working on. As this was my first real code review, I spend time finding resources on the subject. First off, there isn’t a lot of great articles about this subject. Secondly, most of them focus on the code review itself, what to notice, write down etc.
In this blog I want to address the other side of the medal, namely a code review viewed as a developer. Code reviews are for the developers. So it’s important that you, as a developer, understand what is in the review and learn from it.
Why code review matter
Code review are a way to keep the quality of the code at a high. Finding bugs are the second most important thing a code review can accomplish. The most important benefit is when done right, a code review will deal with bugs before they are even written. By enforcing best practices (e.g. design patterns) and principles (Single Responsibility Principle, Liskov Substitution Principle, …) and also coding guidelines such as commenting every method, using describing method names, bugs will actually be avoided because the quality of the code is augmented!
It’s important for you, a developer, to realise that code reviews aren’t for discussing your bad code. See it more are an effort to increase the level of quality in the entire code.
The Cheat Sheet
One nice tip I came across is the use of a cheat sheet. At the start of the code review, all developers should bring a piece of paper. When discussing the review, each developer should write down an issue he/she would be able to write. As a developer, don’t focus on only the code you wrote, but ask yourself the following questions:
- Could I have made the same mistake?
- Did I know about the item, why is was wrong?
- Would I have noticed the code myself?
If you answered yes to any of these question, you should write down the issue on your cheat sheet.
The cheat sheet should be used every time you want to commit code. Take the cheat sheet (really read it) and check the code if something could be coded better. Having the cheat sheet will help you to not introduce items already covered by a code review. Reviewing the same bad code twice is a sign a developer hasn’t learned from the previous review.
Create a positive environment
When reviewing code it’s important to create a surrounding where it’s encouraged to discuss code, where it is a positive thing when code can be improved rather then pick on the one who wrote less then perfect code. As a developer you should keep this in mind as well. Nobody wants to write bad code, so don’t focus on the coder, focus on the code!
Don’t be afraid to discuss code. Sometimes it’s only after a couple of questions that code is really well understood. Sometimes reasons for particular code goes deeper then eyes at first see. A successful code review is a review where developers asked question about code.
Beware of the developer against the world syndrome. It’s normal to take pride on your code. Don’t let the pride come between your code and better code. It’s a learning experience, embrace it and swallow the pride when necessary. That one of the reasons code review are a group thing.
Refrain from negative comments or inappropriate comments. A good example is saying: I would never write that; Who wrote THIS? etc.
Semper paratus
Always be prepared. A great developer will have read the copy before entering the discussion, making the review go faster and the questions more intelligent. It’s just common sense to at least spend a few minutes preparing for any meeting, even internal code reviews.
Anyway, this blog is shorter then I would like. Although code reviews are really important, no matter what kind of project, learning from them is even more important. Take the review serious and you will be rewarded with some extra experience!
Feel free to post any comments about this blog.
Andries

Twitter
LinkedIn
SlideShare
RSS
I couldn’t understand some parts of this article o.us poetry, but I guess I just need to check some more resources regarding this, because it sounds interesting.
Hi Andries,
Good post and i agree with you.
Thanks
Prashant
could you tell us about some not trivial errors in code you did find ?
from what ive seen some errors are just a matter of style, for example should we use multi-ifs for string or should we first convert strings to int/enum and use switch? i remember reading the post when some guy believed that using while with iterator is a bug(i use for, but i have no problem with while).
Great post.
I recently posted about this subject as well. You can find those posts here
http://devlicio.us/blogs/derik_whittaker/archive/2007/06/12/code-reviews-rules-of-the-game.aspx
http://devlicio.us/blogs/derik_whittaker/archive/2007/06/11/code-reviews-how-to-be-successful.aspx
Hi there,
I agree with you, that reviewing your own code is a good thing. It’s possible that you eliminate bugs and reduce useless algorithms.
But sometimes (I know) you’re blind to your own mistakes, so you keep searching hours for the one bug and don’t find it, while somebody else would find it within five minutes.
@ raveman
Big problems we’ve found were a multi-threading issue (Spring PropertyEditor used as a singleton), clear copy pastes, hard-coded id’s refering to database records and some wrong bind-validation-save order (actually validation during binding). I actually believe it’s very hard for a code reviewer to actually spot bugs.
Therefor I focussed my efforts more into getting cleaner code. Using refactoring and strict code style (not absurd strict, but strict to applying simple guides), I wanted to created clearer code that would require less work when maintaining.
I’ve actually find plenty of great examples for good refactoring. I especially love what I’ve learned from reading halve of Refactoring by Martin Fowler (http://martinfowler.com/books.html). Invaluable book if you ask me.
@Derik Whittaker
Great posts! Too bad I didn’t find them 2 weeks ago. Probably wouldn’t have writting this post
@intelligencenetworks
It’s true that developers are blind sometimes to bug they wrote. Keeping the checklist is not to help solve a bug. It’s to find bugs you’ve missed, to keep the code clear so other people will spot bugs very easily and to make it easiery to actually fix a bug in the future.
Keeping the code style about the same, decreases the treshold for other developers to read your code.
Andries, thanks for great post!
I’d like to ask you: to your experience how do you organize code review meetings and how do you choose code for review?
Alexander
I organize the group meeting as a group event. First I pass out the review, with the code snippets I’d like to discuss. Every snippet, I open with the reason why I chose that snippet. Then I discuss alternate implementations, or if it’s trivial I just give the (only) correct answer.
You see, most issues that come from the review aren’t that hard to understand.
The code I’d like to discuss are the ones that show a good solution. Parts of code that deserve a good refactor are my favourite. Ofcourse bugs need to be shown aswell, but mostly this is pretty straightforward.
Hell yeah! This post sounds really good. Reading your blog is useful and interesting. Keep it that way.