Code Review Best Practices

One of the biggest mistakes is not establishing, and documenting a code review process. Without it, your team members won’t understand where, when, or why, they should review code.

START A FREE TRIAL

Copyright © Codacy. All rights Reserved.

THOUSANDS OF COMPANIES USE CODACY TO ANALYSE BILLIONS OF LINES OF CODE. EVERY DAY.

Start shipping quality code today

SIGN UP WITH BITBUCKETSIGN UP WITH GITHUBSIGN UP WITH GOOGLE

By clicking "Sign up" I agree to Codacy's Terms of Service .

2. Define your code standards

3. Review code, not people.

4. Keep a schedule and review early

Creating a schedule is a good way of keeping developers organised, engaged and committed. Code review should also be everyone’s responsibility, so share the load across your entire team.

Many organisations run their code reviews at the end of the development process. However, we’ve found that the teams that run code reviews before deployment, actually spend the least amount of time fixing bugs and making code changes. That's because, by running code reviews earlier in the process, teams are able to improve productivity by identifying issues before programmers waste time building more code on top of already broken code.

So, by reviewing early, and reviewing often, you can reduce code changes and simplify developer peer reviews.

So, you’ve defined your process and set your code quality standards. But that’s useless unless your team can work to an agreed checklist. Even the most experienced developers can fall foul to common mistakes when reviewing the code base. The best way to reduce the probability of errors is to use a checklist that takes into consideration the standards and quality that have been established for your product. Trust us, teams that have a quality standards checklist actually see fewer bugs and have more time to build new features. It’s also a great way to keep control of what's been done, and what still needs to be reviewed.

If you’re doing code reviews properly, the reviewer should have the power to block a pull request from being merged. The benefit in terms of code quality are obvious, but you might be nervous about the impact on your speed of delivery. Don’t be. From the thousands of development teams we speak to, 72% of code reviews are blocking. What’s more, they also have a code quality score that’s 10% higher than the rest! Of course, on the flip-side, reviewers shouldn’t unnecessarily block a pull request because of a subjective “opinion”! Respect the context (and knowledge) that the submitter has and evaluate issues against the agreed checklist.

Ask any group of developers how they define code quality, and you’ll get different answers from all of them. This can cause confusion, frustration, and propagate bad habits across team members.

Define your code quality standards as a team, document them, and stick to them.  Think about code style, API conventions, naming conventions, and readability. It’s one of the most important things you can do to manage technical debt and reduce the amount of time teams spend refactoring code. To avoid arguments, and personal opinion, use an automated code review tool like Codacy, where you can define your code standards and manage them centrally.

It’s not unusual for a developer to spend 0.5- 1 day a week reviewing code, so it’s important that they  understand why certain decisions have been made, and why the code review process is so important to your project (and their own personal development). Unfortunately, some developers feel threatened having their code reviewed by their peers, so set a tone of transparency across your development teams, and explain that the code review process should be welcomed, and is key to greater knowledge sharing and development. The process is there to review code, not them!

1. Define your process

One of the biggest mistakes is not establishing, and documenting a code review process. Without it, your team members won’t understand where, when, or why, they should review code.

Establish a process that works best for the size of your team, their needs, and level of communication they expect. Establish owners of the code review process, and define who will benefit most from the code reviews. Make sure that your process supports your key requirements, including knowledge sharing between more senior developers and engineers, and your more junior team members.  

Your process shouldn't be static, it's always helpful to review best practices every six months and modify based on what's working, and what's not!

So, if you’re just starting out, or perhaps looking to improve your existing process, follow these simple code review best practice guidelines to help you benefit from improved code quality – meaning fewer bugs, and ultimately a reduction in technical debt.

For a more detailed guide, with recommendations drawn from interviews with almost 700 developers, download our “Ultimate Guide to Code Review”.

If you're ready for a better way to review code and improve code quality, try Codacy for free.

Based on research we've conducted across hundreds of development teams, we’ve found that teams with a clear, and effective code review process greatly improve their code quality, so there are fewer bugs to fix. It also means they can ship code faster. In fact, across everyone we surveyed, code reviews were agreed to have had the single biggest impact on code quality!

However, if the code review process is poorly defined, it can be a source of enormous frustration and can even have a negative impact on team performance, with bottlenecks causing deployment delays.

Luckily, based on our research with hundreds of teams just like yours, there are some simple code review best practices you can follow.

7. Use tools that fit your workflow

Unfortunately, the traditional code review processes can be laborious and time consuming. Some teams might even avoid running code reviews purely because of the perceived time wasted, versus the benefits gained.

Code review tools such as Codacy offer new ways to maintain code quality standards and strive to make the code review process easier through automated code review analysis and issue tracking; so your team can be more efficient, deliver better code, and improve code quality across your organisation.