Tips and Tricks for Better Code Reviews

Are you new to code reviews? Do you know what to look for in a code review? Do you feel frustrated with your code review? I’ve been there too. Let’s see some tips I learned and found 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 personally. 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 gets shipped to end users. Sometimes we only need another pair of eyes to spot unnoticed issues in our code.

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

Now that we know what code reviews are good for, let’s 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?

If we’re new to code reviews and we don’t know what it’s going to be reviewed in our code…or if we have been asked to review somebody else code and we don’t know what to look for, we can start looking at this:

Does the code:

It’s a good idea to have a checklist next to us while reviewing the code. We can create our own checklist or use somebody else as a reference. Like Doctor McKayla Code Review Checklist.

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

For the reviewer

Before we start any review, let’s understand the context around the code we’re about to review.

A good idea is to start by looking at the unit tests and look at the “diff” of the code twice. One for the general picture and another one for the details.

If we’re a code reviewer, let’s:

Recently, I found out about Conventional Comments. With this convention, we start our comments with labels to show the type of comments (suggestion, nitpick, question) and their nature (blocking, non-blocking, if-minor).

I use Conventional Comments to avoid tricky or pushy questions during code reviews.

For the reviewee

Before asking someone to review our code, let’s review our own code. For example, let’s check if we wrote enough tests and followed the naming conventions and styling guidelines.

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

If we’re a reviewee, let’s:

For team management

If we’re on the management side, let’s:

Voilà! These are the tips I’ve learned while reviewing other people’s code and getting mine reviewed too. Code reviews can be frustrating. Especially when they end up being a discussion about styling issues and naming variables. I know, I’ve been there.

One of my lessons as a code reviewer is to use short and focused review sessions. I prefer to have short sessions in a day than a single long session that drains all my energy. Also, I include a suggestion or example of the change to be made in every comment. I want to leave clear and actionable comments on every code review.

Of course, I didn’t come up with some of these tips. These are the resources I used to learn how to do better code reviews: NDC’s Code Review Etiquettes 101, Russell Cohen’s How to code review, Smashing Magazine’s Bringing A Healthy Code Review Mindset To Your Team, and FreeCodeCamp’s A Zen Manifesto for Effective Code Reviews.

Happy coding!