A Peer Code Review Process
For Java Development
Copyright © 2002 Thomas J. Clancy
All Rights Reserved
|
Change Summary |
Author |
Date |
|
First Draft |
Thomas J. Clancy |
5/17/02 |
|
Simple revisions. |
Thomas J. Clancy |
11/24/03 |
Table of Contents
2 Steps of the Code Review Process
3 Code Review Scenario Walk-Through
Code review is a very important part of the development process in that it helps to not only determine if the code itself follows the established coding guidelines, but also to help uncover any problems or bugs within the code.
Peer review of code is of course invaluable in this regard because not only does it directly benefit the review process by having programmers themselves review the code (thus helping to ferret out bugs more quickly) but also indirectly—benefiting the company as a whole—since these same programmers tend to review code with which they are unfamiliar; this, of course, helps to distribute knowledge of the code base among the teams rather than have it remain in isolation, worked on and improved by only one or two developers.
Although this document discusses the peer review process in more detail below, it should be noted by the reader that peer code reviews are not intended as a lynching party, where some unsuspecting developer is tied up by the thumbs and held dangling over the proverbial coals while all his or her mistakes are laid bare in front of him for all to mock and ridicule—remember your sensitivity training. No, peer code reviews are simply a way of improving the quality of the code by helping to ensure that the code is written according to the coding standards, that any bugs or problems are discovered and squashed, and that any fundamental mistakes in logic are found before they can cause harm.
This document, then, provides the guidelines and describes the process for holding effective and, I hope, painless code reviews. It also provides a simple, but complete code review checklist based on the established coding standards, that can (and should) be used before actually commencing the peer code review process.
With the advent of more sophisticated tools being designed to help ensure code robustness (e.g. code coverage analysis and style checkers), manages may wish to consider purchasing and investing time in such tools to help reduce the amount and time that developers need to spend doing all of this by hand. For example, a code style checker (e.g. JStyle), could be used to greatly reduce or even eliminate the pre-review process (discussed below). Thus a section is devoted to a simple introduction to the various tools that are available for such purposes.
There are five steps to the code review process that should be relatively simple to follow, and they are briefly described here. They are intended to keep the peer review process as short as possible because a developer’s time is money, and although code review is invaluable, developers need to be doing what they do best: writing code.
Here the steps are briefly defined:
The following sub-sections go into more detail concerning each step.
Acceptance is the means by which code is selected and accepted for review. Usually the team leader or technical manager of a project team selects a portion of code (say a module or several related modules) to be reviewed. If necessary, the code in question is discussed with the team in a team meeting and acceptance of the code is either granted or denied for review.
Once a selection of code has been accepted for review, either the team leader or an appointed developer provides a cursory examination (15 to 20 minutes, for example) of the code to make sure it conforms to within 90% of the checklist that is provided. If it does conform, then the okay is given and the team leader selects, usually randomly, three or four developers and appoints a moderator to perform the peer review. A meeting is then usually scheduled a week from the time the code passes the pre-review process, to actually perform the peer review. Note that it is probably wise to mix both junior and senior level developers within a peer-review team so that junior developers can learn by observing as well as contributing.
Copies of the code to be reviewed are printed out with line and page numbers and distributed to the selected peer-reviewers and the moderator. The developers who are peer-reviewing the code are then encouraged to examine the code in detail, no more than an hour a day, and at least an hour or so in all before the peer-review meeting, so that each developer can make notes as to what he/she believes is wrong with the code, and also to find any further problems in conformance with the coding standards. Doing this kind of review before the actual meeting helps to minimize the amount of time spent within it.
If the code, however, does not conform to within 90% of the checklist provided, this needs to be brought to the team lead’s attention, or if the team lead is doing the pre-review, he needs to bring it to the attention of the developer responsible for the code, at which point the developer will need to revisit the code and sufficiently edit the code to make sure that it does conform to the checklist. This of course would entail actually fixing or rewriting pieces of the code, adding proper comment documentation, etc.
The reason for this pre-review, really, is so that during that actual peer review, very few observations made by the review team will be about code conformance, and more observations will deal with real concerns regarding logic, potential bugs, efficiency problems and perhaps even simple design flaws; but note that the peer review process is not a design review and so more emphasis should be placed on problems and potential bugs within the code, or code improvement.
The purpose of the peer review is for the reviewers to come together and discuss the code being reviewed. These meetings, which are usually an hour to an hour and a half long, are where a consensus is made and a melding of the collective intellect occurs.
A moderator is put in place to make sure that the discussion stays casual and on-target. Which is to say that the discussions between the developers needs to remain focused on bugs or logic problems within the code, or those parts of the code that might have been missed during pre-review that do not conform to the coding standards and guidelines. These meetings are not for reviewing the design of the code or for simply beating to death the coding style—coding style, in fact, should have been caught at the pre-review stage anyway. These meetings are held simply to help catch bugs and logic errors within the code. This is not to say that some comments can’t be made regarding the design and that useful and constructive criticism couldn’t be made, but this should be done after the peer review and probably via email or within a separate meeting (a design review meeting, perhaps).
Often, one of the reviewers or the moderator him/herself is chosen as the scribe for the purpose of taking rigorous notes that reflect the problems encountered and agreed upon by the peer review team (e.g. class name, page number of print out, line number or range of line numbers on the page or pages spanned, method name, and a specific and detailed description of the problem—note that having a notebook computer and a fast typist in these sorts of meetings can be a great advantage over someone who simply has a pen and note paper). These notes are then added afterwards into the bug-tracking tool and assigned to a developer or to the team lead or manager of the group who will then delegate to one or more developers on the team the task of fixing the code.
The revision step is the step where the designated developer or developers fix the bugs that were generated from the peer-review step. Once fixed the bugs are then set as fixed within the bug-tracking tool at which point the post-review can then take place. Note that it isn’t necessary for all bugs to be fixed before a post-review. In fact the team lead or appointed post-reviewer could be reviewing the bugs fixes as they occur in parallel with the revision step as bugs are being fixed and checked in.
Post-review, which may be optional, is where the team lead or a designated developer checks to make sure that the bug fixes and general revisions conform to the problems discovered through the peer review process. This doesn’t necessarily mean that all bugs were found and fixed, but this should ensure that the ones that had been found during the peer review step were resolved correctly, which might entail a simplified version of peer review or even via pair programming as described in the Extreme Programming software development process.
This section shows a walk-through of a typical code-review scenario.
Class Name:_______________________________________
Reviewer:_________________________________________ Date:________________
Code Format Conformance:
Coding Standard Conformance:
Javadoc and General Documentation Conformance:
Exception Conformance:
To score, treat all Yes answers as 1, all No answers as -1 and all N/A answers as 0. Add all answers and calculate the percentage to determine the completeness of the code covered by this checklist.
[1] EJS refers to the Elements of Java Style book that we use as a guide for code conformance. The number next to each reference refers to a rule within the book.