Tips and Tricks for Better Code Reviews

You’re new to code reviews? You don’t know what to look for in a code review? You feel frustrated with your code review? It’s true that code reviews can be frustrating for the reviewer and the reviewee. Let’s see how to improve our code reviews.

Code review is a stage of the software development process where a piece of code is examined to find bugs, security flaws and other issues. Often reviewers follow a coding standard and style guide while reviewing code.

TL;DR

  1. For the reviewer: Be nice. Remember you are reviewing the code, not the writer.
  2. For the reviewee: Don’t take it personal. Every code review is an opportunity to learn.
  3. For all the dev team: Reviews take time too. Add them to your estimates.

Advantages of Code Reviews

Code reviews are a great tool to identify bugs before the code head to the QA team or your end users. Sometimes you need another pair of eyes to spot unnoticed things in your code.

Also, code reviews ensure the quality of the code doesn’t degrade as the project moves forward. They help to spread knowledge inside a team and mentor newcomers or juniors.

Now that we know what code reviews are good for, let’ see what to look for during code reviews and tips for each role in the review process.

What to look for in a code review?

Are you new to code reviews and you don’t know what it’s going to be reviewed in the code you wrote? Or have you been asked to review somebody else’s code and you don’t know what to look for? You can take a look at this:

Does the code…

It’s a good idea to have a checklist next to you while reviewing code. You could create your own checklist or start using Doctor McKayla Code Review Checklist.

Tips and tricks for better code reviews
Photo by Charles Deluvio on Unsplash

For the reviewer

Before you start any review, make sure to understand the requirements. Start by looking at the unit tests, they should be like documentation.

It’s a good idea to look at the diff of the code twice. One for the general picture and another one for the details.

Recently, I found out about conventional comments. The basic idea of this convention is to prefix comments with labels to show the type of comments (suggestion, nitpick, question) and the nature of them (blocking, non-blocking, if-minor).

For the reviewee

Before asking someone to review your code, review your own code. Check if all tests are passing, classes and methods follow naming conventions, new code comply to styling guidelines.

It’s a good idea to wait for the CI/CD to build and run all tests before asking someone to review your changes or assign reviewers in a tool. This will save time to your reviewers and you.

For team management

Voilà! You may feel frustrated with code reviews, either as reviewer or reviewee. Sometimes, reviews could end up being a discussion about styling issues and naming variables. I know, I’ve been there…But, be humble and nice! Every code review is a chance to learn something new.

These are some of the resources I used to compile this list of tips.

Happy coding!