Effective Code Reviews

Code review is the process in which code written by a developer is inspected by another person to look for defects and improvements. In other words, developers work on their code mostly in isolation and call for a review when they are ready.

Code reviews are a proven way to increase software quality. At Google, all code is peer reviewed. To quote a few examples from Code Complete 2:

  • IBM’s 500,000 line Orbit project used 11 levels of inspections. It was delivered early and had only about 1 percent of the errors that would normally be expected.
  • A study of an organization at AT&T with more than 200 people reported a 14 percent increase in productivity and a 90 percent decrease in defects after the organization introduced reviews.
  • Jet Propulsion Laboratories estimates that it saves about $25,000 per inspection by finding and fixing defects at an early stage.

However, many teams still struggle with effective code reviews and don’t reap full benefits. In dysfunctional teams and organizations, it can quickly turn into a nasty experience for everyone involved:

In this post, I’ll talk about few things teams and organizations could do to make code reviews a pleasant experience for everyone involved.

Advice to Management: Create the Right Culture

Effective code reviews require a healthy culture that values quality and excellence. Code reviews will not give you the desired results if the team doesn’t believe in delivering high-quality products. You need a positive culture in which people are engaged – one that thrives on constructive criticism and allows the best ideas to win.

Other than creating a great culture and allowing time and resources to conduct reviews, management role in reviews should be kept to a minimum. It’s cultural and most people don’t want to air their dirty laundry in front of their superiors. Code reviews are best conducted by peers and management should never ask for details it could use to judge people – yes, some managers require check-lists and grades to be produced so they can “measure” and judge people.

May be you already have a great culture (count yourself lucky). May be you are half-way there. Creating the right culture depends on many factors (both internal to the team and organizational). It can be extremely challenging and there is no magic formula. Without the right culture, code reviews will not bring desired gains or at extremes, could become counter-productive.

Everyone: Remember the Human

In his book, Peer Reviews in Software: A Practical Guide, Wiegers writes:

The dynamics between the work product’s author and its reviewers are critical. The author must trust and respect the reviewers enough to be receptive to their comments. Similarly, the reviewers must show respect for the author’s talent and hard work. Reviewers should thoughtfully select the words they use to raise an issue, focusing on what they observed about the product. Saying, “I didn’t see where these variables were initialized” is likely to elicit a constructive response, whereas “You didn’t initialize these variables” might get the author’s hackles up.

It is easy to become fixated on the code, but remember, there’s a human at the other end of the table (or computer). A human who has opinions. A human who is entitled to have an ‘ego’. Remember that there are many ways to solve a problem.

Advice to Reviewers: Be Humble

Some of these things won’t work if they come off as rehearsed or said in a sarcastic tone. Treat the code review as you would a normal conversation. You are listening to another person and should genuinely seek to understand their perspective. Offer suggestions and tips when they are necessary. If the code is great, don’t be compelled to find something negative to say about it.

Advice to Developers: It is not Personal

Summary

Peer reviews are about people interacting with one another and ineffectiveness stems from sociological issues. Yet managers spend a lot of time worrying about which shiny tools to use – while tools will help, they alone won’t magically bring the results. Start with the right culture and… remember the human:-)

I would love to hear your feedback, comments, thoughts on conducting effective code reviews. Please leave a comment below.

This article was written by Umer Mansoor. Please leave your comments below and like on Facebook or follow on Twitter to stay up-to-date.

Subscribe to Code Ahoy

Join today and be the first to get notified on new updates.

comments powered by Disqus