Everyone needs a code review

I’ve been writing code for a long time and now that I’m an Architect at my company, people look at me funny when I ask them to review my code. Many folks think that I don’t need code reviews.

My feeling on the matter is that everyone needs a code review. Code reviews don’t have to be long formal meetings with code printouts and red pens to mark all the issues. A simple peer review before checking your changes into the Source Control System may be all that is needed in many cases.

Here’s a recent example of a quick change I made to code and pushed through to production. It was such a small change that I didn’t think to get it reviewed. Now, I wish I had as we’re having to make an off-cycle release of the code to fix the bug that I introduced.


if(log.isDebugEnabled())
{
  if (in != null)
  {
    log.debug("Incoming object list size: " + in.size());
    for(ContentInstance ci:in)
     {
       try
       {
         DocumentTransferObject dto = getDTOfromContent(ci);
         TOList.add(dto);
       }
       catch (VCMContentRetrievalException e)
       {
         log.warn("Unable to retrieve content.", e);
       }
     }
   }
   else
   {
     log.debug("Incoming object list is null.");
   }
}

As you can see, I accidentally included some code in an if block that only gets executed if my Log4J log level is set to Debug. This code ran perfectly well on our development and test environments, but failed on our production server where we don’t normally run with Debug logging enabled.

So, lots of things went wrong here, but I present it as an example of something that would have been easily caught in a code review, and as proof that even experienced programmers can make dumb mistakes.

One thought on “Everyone needs a code review”

Leave a Reply

Your email address will not be published. Required fields are marked *