Code Review

Layers of Management ThoughtLayer 10: Practices and RitualsPracticeAlso known as Peer code review, Code inspection, Fagan inspection

From Michael Fagan's formal inspections at IBM, set out in Design and code inspections to reduce errors in program development (1976), the forerunner of the lighter, tool-based review most software teams now run.

Has someone other than the author read every change to software before it joins the shared product, catching defects where they are cheapest to fix and spreading knowledge of the code across the team.

A quarter's hundred defects, fixed in review or after clients find them

The tax-engine team's quarter: code that would ship about 100 defects, three hundred hours spent reviewing it, one hour to fix a defect caught in review. Set how many defects review catches and what a client-found defect costs, and watch whether review pays for itself. Illustrative.

60%
30 hours
Hours saved in the quarter
1,440 hours
Verdict
Review costs more than it saves at these numbersReview pays for itself
Defects that reach clients
40 of 100

Hours spent on the quarter's defects, review includedHours with no review

02,0004,0006,0003,0001,560No reviewWith review02,0004,0006,0003,0001,560No reviewWith review

An example

A payroll software company's tax-engine team had dropped code review during a crunch year, and defects reported by clients climbed to about a hundred a quarter. Each cost around thirty hours by the time support had diagnosed it, an engineer had patched it, and an account manager had explained the error to the client.

The engineering director brought review back with three rules taken from formal inspection. Reviewers worked from a checklist built from the past year's defects, led by tax rounding and date boundaries. They read no more than about four hundred lines in one sitting. And every defect a review found went into a log. Changes to tax tables needed a second reviewer. Reviews took about three hundred hours a quarter. Within two quarters they were catching around six defects in ten before release, and client-reported defects fell to about forty. The log showed date-boundary errors as the largest group, so the team built one shared date library, and that category all but disappeared.

The core idea

Code review is the practice of having someone other than the author examine a change to software before it joins the shared product, to find defects, check design and security, and spread knowledge of the code. It ranges from formal inspection, with set roles, a meeting, checklists, and recorded defects, to the light review most teams now do in a tool, where one or two colleagues read a change and comment before it merges.

Its logic is economic. A defect costs least to fix close to where it was made, by the person who made it, before anything depends on it, and it costs most once customers have met it. A second reader catches what the author cannot see, because the author reads what they meant to write. Review also leaves a by-product that teams come to value: more than one person understands each part of the code. A 2013 Microsoft study by Alberto Bacchelli and Christian Bird found that reviews yielded fewer defects than people assumed, and more shared knowledge, team awareness, and alternative designs.

The thinking behind it

Michael E. Fagan Michael Fagan, an IBM engineer, set out formal inspection in Design and code inspections to reduce errors in program development (1976). He treated programming as a process to plan, measure, and control, with inspections as its checkpoints: about four people, led by a trained moderator from outside the project, moving through an overview, individual preparation, a meeting whose only job is to find errors, rework, and follow-up. Every error was classified and counted, so the data could sharpen the next checklist. His case was economic: rework done early cost 10 to 100 times less than late, and on one applications project, inspections found 82 percent of the errors and the work came in 25 percent under its estimated programmer days.

Where it sits in the layers

Code review is a practice of Layer 10, the routine where a software organization's ideas about quality meet each change. It assumes what Total Quality Management holds in Layer 6, that defects are cheapest to catch near their source and that defect data should improve the process, and methodologies in Layer 8 such as Extreme Programming build it into their routines. Its modern forms sit beside it in Layer 10, as Pull-Request Review and Pair Programming. A defect log sorted with Pareto Analysis, a Layer 9 tool, shows which checklist items earn their place. The common mistake is asking review to stand in for testing. Reviewers find kinds of defects that tests miss and miss kinds that tests find, so a team that cuts testing because every change is reviewed ships the second kind.

How organizations put it to work

Code review is owned by engineering leadership as a standard and by each team as a habit. The standard says which changes need review (in most teams, all of them), how many reviewers sensitive areas need, what reviewers check, and how quickly a review must start. Teams that get the most from it borrow three things from formal inspection: a checklist built from their own recent defects, limits on how much code is read at once and for how long, and a record of what reviews find, so the checklist and the coding standards improve over time.

Review changes routines and knowledge more than structure. Every change has a second reader, newer engineers learn the system from senior reviewers and the reverse, and no part of the code is understood by only one person. Measures worth tracking are defects found in review against defects found later, time from request to review, and how widely reviewing is spread across the code.

In the first year, expect slower merges at first, arguments over style that tooling should settle, and reviewers who wave large changes through. The return is fewer defects reaching customers, less rework, and a code base that does not depend on any one engineer.

Where it goes wrong

The first failure is the rubber stamp. Reviewers approve changes too large or too unfamiliar to read, and review turns into a formality. Spot it when large changes are approved as quickly as small ones, without comments.

The second is the style war. Reviews fill with remarks on naming and formatting, real defects slip through, and authors come to resent the process. Spot it when most comments could have come from a formatter or a linter.

The third is review without learning. Defects found in review are fixed and forgotten, so the same kinds return. Spot it when no one can say which defect types reviews catch most often. Fagan's own figures show the price of thoroughness: by his conservative estimate, four people inspecting a thousand statements of systems code spent 90 to 100 people-hours from overview to follow-up, which is why most teams now run a lighter review and trade some of inspection's rigor for speed.

Related and rival frameworks

  • Pull-Request Review. The asynchronous, tool-based form most teams use today. The better fit for distributed teams and open-source projects.
  • Pair Programming. Reviews continuously, as the code is written. Better for complex or risky work, at the cost of two people's time on one task.
  • Mob Programming. Puts the whole team on one change at one screen, so review happens with the work. Suits hard problems where shared understanding matters most.

Go to the source

Back to the catalog