Contents

The Standard of Code Review: Striking a Balance Between Quality and Progress

As software engineers, we know the importance of code review in maintaining the overall health of a codebase. However, code review can often become a source of frustration when reviewers demand perfection and delay progress. In this article, we’ll explore Google’s standard of code review and how it strikes a balance between quality and progress.

Balancing Progress and Quality

The primary purpose of code review is to ensure that the overall code health of the system is improving over time. This requires a delicate balance between allowing developers to make progress on their tasks and ensuring that each change is of sufficient quality to improve the codebase. The codebase should not degrade through small decreases in code health over time, even when teams are under significant time constraints.

The Senior Principle of Code Review

Google’s standard of code review is straightforward: reviewers should approve a change once it is in a state where it definitely improves the overall code health of the system being worked on, even if the change isn’t perfect. This principle emphasizes the need to make forward progress while maintaining the code’s maintainability, readability, and understandability.

No Such Thing as Perfect Code

It’s essential to remember that there is no such thing as perfect code—only better code. Reviewers should not require authors to polish every tiny piece of a change before granting approval. Instead, they should balance the need to make progress with the importance of the changes being suggested. A change that, as a whole, improves the maintainability, readability, and understandability of the system should not be delayed for days or weeks because it isn’t “perfect.”

Mentoring through Code Review

Code review can also be a powerful tool for teaching developers new things about a language, framework, or general software design principles. Leaving comments that help a developer learn something new is always a good idea. Sharing knowledge is part of improving the code health of a system over time. However, reviewers should prefix educational comments that are not mandatory with “Nit: “ or indicate that it’s not mandatory for the author to resolve them in this change.

Principles to Follow

Google’s standard of code review is based on principles, not personal opinions or preferences. Technical facts and data should always overrule opinions and personal preferences. On matters of style, the style guide is the ultimate authority. If a style point is not in the guide, it is a matter of personal preference, and the style should be consistent with what is there. Aspects of software design should be weighed on underlying principles, not personal opinion. When several approaches are equally valid, the author can demonstrate (either through data or solid engineering principles), and the reviewer should accept the author’s preference.

Resolving Conflicts

When conflicts arise in a code review, the first step should always be for the developer and reviewer to try to come to a consensus, based on the contents of this document and other related documents. If consensus is challenging to reach, a face-to-face meeting or video conference between the reviewer and author can be helpful. If that doesn’t resolve the situation, the most common way to resolve it is to escalate the issue to a broader team discussion, technical lead, code maintainer, or engineering manager. Delaying a change because of an unresolved conflict is not acceptable.

Conclusion

In conclusion, code review is a critical aspect of software development that helps ensure the quality, maintainability, and readability of code. A code review process that is efficient, effective, and consistent can lead to better code health and fewer bugs in the long run.

By following the standard of code review outlined in this article, software engineers can strike a balance between making forward progress and improving the overall code health of their system. They can also foster a culture of continuous improvement, where code review is not just about finding faults but also about learning and sharing knowledge.

As software engineering continues to evolve, the importance of code review will only increase. By implementing a robust code review process, software engineers can stay ahead of the curve and produce high-quality, maintainable code that meets the needs of their users.