Article Image

Six best practices to improve your code reviews

13th May 2021 By Marcelo Sousa

Code reviews are complex. They involve good time management, high emotional intelligence, knowledge of the codebase, and technical expertise. It is a team process where practice and communication are everything. In this post, we share six key practices that software development teams are doing to elevate the quality of their code reviews.

1. Review your pull requests before Others

By reviewing your pull requests before asking for other reviews, you are first checking that your pull request is reviewable. If you can’t understand the code changes or go over them in a reasonable time you immediately realize that others will probably face the same difficulties. Also by reviewing your code first, you can save review iterations by spotting and fixing minor inconsistencies. Write pull requests to your future self.

2. Encourage reviewers to be co-owners

There’s a tendency among reviewers to treat comments as sticky notes. Reminders. Things that will call your attention to a problem. You’ll see things like “Fix this”, or “To do”, all the time.

This isn’t ideal because reviewers are playing the role of gatekeeper which will inevitably lead to friction associated with the inherent power dynamics.

By encouraging reviewers to play the role of co-owners you are establishing a common goal between the stakeholders in the process.

A concrete way of doing this is to treat comments as written thoughts while you are going through the changes. This will inevitably lead to a lot of questions. Why does this need fixing? How would you go about it? Do you have suggestions, or guidance? 

Still, if you have these questions, probably someone else will too. Do not be afraid to share your doubts and questions about the code. You took the time to go through the changes. Document this knowledge.

Remember that not every comment needs to be resolved.

3. Leverage automation

Automation is key to improving the quality of code reviews. Understand why you are asking for a review. If you are looking to merge a pull request, ensure that the code compiles and the tests are passing. Use automation as a safety net to prevent reviews or merges of code changes that are fundamentally broken.

Dedicate time to set up automation that can save you and your team a lot of time and useless review iterations.

4. Always have a reviewer in mind

Never (ever!) approach a group of people asking for reviews. This means slack channels, group emails, or any other form of communication that will essentially amount to asking for a volunteer. People are busy. They will always secretly expect someone else to answer, and time will be wasted. It will also generate resentment towards the task of code reviewing, making it feel like something extra to do, aside from your actual work. This isn’t true or fair.

Ask someone ahead of time for a review, and let them know as soon as the review can start. This way, they can set aside time to do it and there will be no roadblocks.

5. Time your code reviews 

It’s important to keep metrics that help you understand where roadblocks are and in what ways you can improve your workflow. If you time your code reviews, you will always know how long they took you. You will learn how fast you can tackle specific issues, and which parts of the codebase are hard to review.

Metrics are a great way to improve your own productivity and to start conversations on how to balance the review load and improve the overall review process.

6. Create a top 10 list of pull requests

Treat code reviews like amazing feats of skill. Sports managers improve their athletes’ performance by selecting footage for them to watch, and you should be doing pretty much the same.

Find pull requests that illustrate specific practices you think your team can learn from. How to leave perfect comments that are actually helpful. How to detect the kinds of problems a developer typically misses. How to illustrate a problem effectively so that someone can pick it back up even months later.

Always have this top 10 available for developers to look at and derive inspiration from. Use it often in learning sessions.

Try Reviepad
Disrupting how software developers collaborate