Bookmarks

Code review

A team development practice in which colleagues read code changes before they are merged, find mistakes and suggest improvements.

Also: peer review, code inspection, reviewing code

checked 9 Nov

All terms

Code review is a systematic check of changes by other people before they reach the main branch. The author posts the changes for review, colleagues read them and point out what to fix. As a result fewer bugs reach the codebase, and the team keeps a consistent style and shares knowledge.

How a review goes

StageWhat happens
Submitting for reviewthe author prepares a pull request (PR) with a small number of changes and describes what was done and why
Reading and commentsthe reviewer reads the code and leaves comments: what to fix, what to clarify, where there is a simpler option
Fixesthe author replies or reworks the code; disputed points are discussed, and a third developer is brought in if needed
Decisionon Git hosting services such as GitHub, the reviewer leaves Comment, Approve or Request changes; once approved, the pull request is merged into the main branch

What is checked

  • Soundness of the solution: how the change fits into the system and whether it duplicates existing mechanisms; for a reviewer this matters more than small style points.
  • Correctness: whether the code solves the task and whether there are logic errors or unhandled cases.
  • Security: handling of user input, handling of secrets, access rights.
  • Clarity: clear names, a consistent style, no unnecessary complexity.
  • Tests: whether they are added in the same change and whether they catch real bugs rather than passing only on paper.

How much code and how much time

The smaller the change, the more carefully it is reviewed. In Google’s code review guide, a reasonable size is around a hundred lines, and a change of a thousand lines is usually too large: the reviewer may ask for it to be split into parts. The response to a review request is limited there to one working day: long waits slow down the whole team and push authors to look for ways around the process.

Forms of review

One of the first formalised review procedures was Michael Fagan’s inspection at IBM, which he described in a 1976 paper as a formal meeting with defined roles and a checklist-based search for defects. Today the main form is reviewing pull requests on a Git hosting service; there are also group walkthroughs and pair programming, where two people write the code together from the start. Perfection is not required in review: a change is approved if it improves the state of the codebase, and minor comments are marked Nit:, meaning they do not have to be fixed.

Sources

the term is written from these pages

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

In depth in the references

where the topic is covered in detail