When working on a project with multiple developers, code reviews are critical to the success of the project. Code reviews provide an opportunity to share knowledge and ensure code adheres to the standards agreed upon by the team. If not conducted effectively code reviews can be a source of resentment for teams. Today, we will discuss what we have found to be key components of effective code reviews.

Goals

Effective code reviews begin with having a measurable goal in mind. Before you can determine the effectiveness of your code reviews, you must determine how you will measure effectiveness. There are many metrics available to track the effectiveness of code reviews. Some of the most common metrics include:

  • Defect Density - number of defects / size of release (e.g. lines of code)
  • Defect Removal Efficiency - (Number of defects found internally / (Number of defects found internally + Number of defects found externally) ) × 100

Defect density helps to identify features that may be more complex or pose a higher risk of causing issues. Defect removal efficiency informs us of how effective our testing practices are. The higher the efficiency the fewer defects identified by customers.

Checklist

Code review metrics are our north star and hold us accountable, but they don't provide the direction and guidance needed to get us there. This is where having a code review checklist helps. Creating a checklist helps to reiterate the purpose of code reviews and sets expectations for both the reviewers and the submitter.

At TG4 Solutions, are checklist for code reviews contains the following:

  • Does this pull request meet all of the acceptance criteria?
  • Is there opportunity for abstraction?
  • Does every class or function exist for a reason?
  • Does this functionality already exist within the project or a library?
  • Would I have solved this differently?
  • Are there any side effects to this solution?
  • Was the external documentation updated?

Our checklist is a high level list of questions that allow reviewers to tap into their unique expertise. We also want to prevent reviewers from just checking only for what is on the list, which tends to happen when you have an extensive list explicitly explaining what should be checked for.

Our checklist helps our developers focus on functionality, maintainability, and best practices, while leaving the rest to static code analysis tools and style guides.

Commitment

Commitment from both code reviewers and code submitters is paramount to successfully conduct effective code reviews. Adhering to the process is critical to the success of your checklist and goals. Every team member should be an active participant in code reviews and make an effort to review pull request in a timely manner. To help with the latter, we have each developer block off 30 minutes in the morning and in the afternoon specifically for conducting code reviews. This ensures that all PRs are reviewed within a 24 hours.

We understand that there isn't a one size fits all solution for effective code reviews as each team's composition and process are unique. However, by having a goal, a checklist, and team commitment the process will inevitable get better over time.

Let us know how adding these components into your process works out for you.

What makes an effective code review