What is a code review?

A code review is a peer review of code that helps developers ensure or improve the code quality before they merge and ship it.

What are code reviews, and how do they work?

Code reviews, also known as peer reviews, act as quality assurance of the code base.

Code reviews are methodical assessments of code designed to identify bugs, increase code quality, and help developers learn the source code.

After a software developer has completed coding, a code review is an important step in the software development process to get a second opinion on the solution and implementation before it’s merged into an upstream branch like a feature branch or the main branch. The reviewer can also act as a second step in identifying bugs, logic problems, uncovered edge cases, or other issues.

This practice empowers code authors and reviewers alike to identify security flaws, adhere to quality standards, and share knowledge across programming languages and frameworks. Reviewers can be from any team or group as long as they’re a domain expert. If the lines of code cover more than one domain, two experts should review the code.

Why are code reviews important?

Developing a strong code review process sets a foundation for continuous improvement and prevents unstable code from shipping to customers. Code reviews should become part of a software development team’s workflow to improve code quality and ensure that every piece of code has been looked at by another team member.

The code review process is also an important part in spreading knowledge throughout an organization. For those reasons and more, 76% of developers who took the 2022 Global DevSecOps Survey said code reviews are “very valuable.”

What are the benefits of code reviews?

What are the disadvantages of code reviews?

Four approaches to code review

Some of these disadvantages can be minimized by selecting the most appropriate code review method for your team. Here are four common approaches to code review:

Pair programming

Pair programming involves two developers collaborating in real time — one writing code (the driver) and one reviewing code (the navigator). Pairing sessions are popular with development teams because teammates collaborate to identify the most effective solution to a challenge. Team members share knowledge and can quickly overcome difficulties by working through ideas together and drawing on their expertise.

The benefits of pair programming

The drawbacks of pair programming

Over-the-shoulder reviews

In an over-the-shoulder-review, two developers — the author and reviewer — team up in person or remotely through a shared screen and the author explains the completed change proposal and offers reasoning for the chosen solutions. The reviewer asks questions and makes suggestions, similar to how team members collaborate during pairing sessions. The author can make small changes during the review and note larger fixes for a later time.

The benefits of over-the-shoulder reviews

The drawbacks of over-the-shoulder reviews

Tool-assisted reviews

Teams may decide to use tools to save time and ensure the highest quality code is shipped. Tool-assisted reviews can automatically gather changed files and display the differences, or make it easier to provide feedback and have conversations via comments, and incorporate things like static application security testing (SAST) to help identify and remediate vulnerabilities.

The best way to look at tool-assisted reviews is to consider them a complement to other types of reviews. Automated tooling is an effective way to enforce code standards, identify vulnerability, gather metrics, and gather files, but some teams may be tempted to completely rely on tooling and forgo team member involvement to conduct code reviews. Tools should be viewed as an extension of code reviews and a way to enhance the process.

The benefits of tool-assisted reviews

The drawbacks of tool-assisted reviews

Email pass-around

Email pass-arounds are often used for minor difficulties and small pieces of code. They can be conducted via email or source code management systems. During an email pass-around, an author sends an email containing code changes to reviewers. Email pass-around is similar to over-the-shoulder reviews in that they can be easily implemented and don’t require a strong learning curve or a mentoring stage to teach the author how to make a change.

The benefits of email pass-arounds

The drawbacks of email pass-arounds