Code Review Types
Code Review Types
There are many ways to skin a cat. I can think of four right off the
bat. There are also many ways to perform a peer review, each with
pros and cons.
Formal inspections
For historical reasons, “formal” reviews are usually called “inspec-
tions.” This is a hold-over from Michael Fagan’s seminal 1976
study at IBM regarding the efficacy of peer reviews. He tried many
combinations of variables and came up with a procedure for
reviewing up to 250 lines of prose or source code. After 800
iterations he came up with a formalized inspection strategy and
whom to this day you can pay to tell you about it (company name:
Fagan Associates). His methods were further studied and ex-
panded upon by others, most notably Tom Gilb and Karl Wiegers.
22 / Best Kept Secrets of Peer Code Review
Planning
- Verify materials meet entry criteria.
- Schedule introductory meeting.
Introductory Meeting
- Materials presented by author.
- Moderator explains goals, rules.
- Schedule inspection meeting.
Readers and
reviewers inspect
the code privately.
Inspection Meeting
- Materials reviewed as a group.
- Defects logged.
- Metrics collected by recorder. If no defects
are found, the
review is
complete.
Rework
- Author fixes defects alone.
- Metrics collected by author.
- Verification meeting scheduled. If additional
defects found,
the inspection
repeats.
Verification Meeting
- Reviewer verifies defects fixed.
Complete
- Done!
Follow-Up Meeting
- How could the inspection process be
improved?
Over-the-shoulder reviews
This is the most common and informal of code reviews. An
“over-the-shoulder” review is just that – a developer standing over
the author’s workstation while the author walks the reviewer
through a set of code changes.
Typically the author “drives” the review by sitting at the key-
board and mouse, opening various files, pointing out the changes
and explaining why it was done this way. The author can present
the changes using various tools and even run back and forth
between changes and other files in the project. If the review sees
1 See the Votta 1993 case study detailed elsewhere in this collection.
2 See the case study survey elsewhere in this collection for details.
Five Types of Review / 25
Preparation
- Developer finds available reviewer in person or
through shared-desktop meeting.
Inspection Meeting
- Developer walks reviewer through the code.
- Reviewer interrupts with questions.
- Developer writes down defects
Rework
- Developer fixed defects in code.
something that clarifies the code to the reviewer, but the next
developer who reads that code won’t have the advantage of that
explanation unless it is encoded as a comment in the code. It’s
difficult for a reviewer to be objective and aware of these issues
while being driven through the code with an expectant developer
peering up at him.
For example, say the author was tasked with fixing a bug
where a portion of a dialog was being drawn incorrectly. After
wrestling with the Windows GUI documentation, he finally
discovers an undocumented “feature” in the draw-text API call
that was causing the problems. He works around the bug with
some new code and fixes the problem. When the reviewer gets to
this work-around, it looks funny at first.
“Why did you do this,” asks the reviewer, “the Windows GUI
API will do this for you.”
“Yeah, I thought so too,” responds the author, “but it turns
out it doesn’t actually handle this case correctly. So I had to call it
a different way in this case.”
It’s all too easy for the reviewer to accept the changes. But
the next developer that reads this code will have the same ques-
tion, and might even remove the work-around in an attempt to
make the code cleaner. “After all,” says the next developer, “the
Windows API does this for us, so no need for this extra code!”
On the other hand, not all prompting is bad. With changes
that touch many files it’s often useful to review the files in a
particular order. And sometimes a change will make sense to a
future reader, but the reviewer might need an explanation for why
things were changed from the way they were.
Finally, over-the-shoulder reviews by definition don’t work
when the author and reviewer aren’t in the same building; they
probably should also be in nearby offices. For any kind of remote
review, you need to invoke some electronic communication. Even
28 / Best Kept Secrets of Peer Code Review
Code Check-In
- Developer checks code into SCM.
- SCM server sends emails to reviewers based
on authors (group leads) and files (file owners).
Inspections
- Recipients examine code diffs on their own
If no problems,
recognizance.
review fades into
- Debate until resolved or ignored.
“Complete.”
Rework
- Developer responds to defects by making
changes and checking the code in.
- Nothing special to do because code is already
checked into version control.
Complete
- Nothing special to do because code is already
checked into version control.
- Don’t really know when in this phase because
there’s no physical “review” that can complete.
3 For a fun read on this topic, see “Where do These People Get Their (Unorigi-
nal) Ideas?” Joel On Software. Joel Spolsky, Apr 29, 2000.
Five Types of Review / 31
Preparation
- Developer gathers changes together.
- Developer sends emails with changes.
Inspections
- Recipients examine code diffs on their own
recognizance.
If no problems,
- Debate until resolved.
no rework
- Developer keeps it going (“Are we done yet?”)
required.
Rework
- Developer responds to defects by making
changes and re-emailing the results.
Complete
- Developer checks changes into version control.
- Participants could get notified via server email.
Tool-Assisted reviews
This refers to any process where specialized tools are used in all
aspects of the review: collecting files, transmitting and displaying
files, commentary, and defects among all participants, collecting
metrics, and giving product managers and administrators some
control over the workflow.
There are several key elements that must be present in a re-
view tool if it is going to solve the major problems with other types
of review4:
different essay in this collection; this section will discuss general ways in which
tools can assist the review process.
34 / Best Kept Secrets of Peer Code Review
also need to make sure the tool is flexible enough to handle your
specific code review process; otherwise you might find the tool
driving your process instead of vice-versa.
Although tool-assisted reviews can solve the problems that
plague typical code reviews, there is still one other technique that,
while not often used, has the potential to find even more defects
than standard code review.
Pair-Programming
Most people associate pair-programming with XP5 and agile
development in general, but it’s also a development process that
incorporates continuous code review. Pair-programming is two
developers writing code at a single workstation with only one
developer typing at a time and continuous free-form discussion
and review.
Studies of pair-programming have shown it to be very effec-
tive at both finding bugs and promoting knowledge transfer. And
some developers really enjoy doing it.
There’s a controversial issue about whether pair-programming
reviews are better, worse, or complementary to more standard
reviews. The reviewing developer is deeply involved in the code,
giving great thought to the issues and consequences arising from
different implementations. On the one hand this gives the
reviewer lots of inspection time and a deep insight into the
problem at hand, so perhaps this means the review is more
effective. On the other hand, this closeness is exactly what you
don’t want in a reviewer; just as no author can see all typos in his
own writing, a reviewer too close to the code cannot step back and
critique it from a fresh and unbiased position. Some people
suggest using both techniques – pair-programming for the deep
review and a follow-up standard review for fresh eyes. Although
Conclusion
Each of the five types of review is useful in its own way. Formal
inspections and pair-programming are proven techniques but
require large amounts of developer time and don’t work with
remote developers. Over-the-shoulder reviews are easiest to
implement but can’t be instantiated as a controlled process. E-mail
pass-around and tool-assisted reviews strike a balance between
time invested and ease of implementation.
And any kind of code review is better than nothing.