Code review, explained

What is code review?

Code review is the practice of having someone other than the author read a code change before it is merged. The reviewer checks that the change is correct, readable and safe, asks questions and suggests fixes. On most teams today it happens in a pull request or merge request, and the change merges only after a reviewer approves it.

Updated

Why teams do it

Catching bugs is the reason most people give. A well-known study of code review at Microsoft (Bacchelli and Bird, 2013) found that finding defects remains the main motivation, but that reviews turn out to be less about defects than expected and bring other benefits: knowledge transfer, wider team awareness and alternative solutions to problems. More than one person understands each part of the system, and the team's conventions spread.

What a reviewer looks for

Keeping reviews useful

Small changes get better reviews than large ones. Let machines check what machines can, such as formatting, lint rules and tests, so reviewers spend their attention on logic and design. Agree on what blocks a merge and what is only a suggestion, and say which one a comment is.

Security review inside code review

Security bugs are easy to miss in an ordinary review, because the vulnerable line often looks normal. The problem is where the data came from, several files away. Automated security review helps here.

pokayoke is one such reviewer for GitHub. It reviews every push and pull request on the repositories you connect, runs exploits to prove the vulnerabilities it can, and marks each finding proven or not.