Wu Jiayi

Effective code review (part 1): requesting review

code-reviewgithub

Why do we code review?

There are two main reasons why code review is important:

  1. Shifting left: Code review can help identify issues earlier, allowing for the prevention of many production bugs during the code review stage.

  2. Learning and knowledge sharing: Code review provides a valuable opportunity for team members to learn from each other and share knowledge.

What could go wrong?

code review There is a spectrum of code review styles:

The best code review lies somewhere in between, but what does a good code review look like?

Code review is a two-way street

A successful review requires good interactions between the author and the reviewer:

In the rest of this post, we will discuss tips that you can use as a code author when requesting a code review.

Principles for requesting a code review:

1. Make the pull request (PR) small

Avoid gigantic PRs. It is a disastrous feeling to see a PR with 100+ file changes. The reviewers might simply rubberstamp the PR because it is too difficult to review. Try to break big changes into smaller PRs. In fact, the task ticket itself should be broken down into smaller tickets in the first place.

2. Write clean git commits

A clean git commit history makes it much easier to understand the changes. It requires additional effort to maintain a clean commit history, but the reviewer and your future colleagues will thank you for it.

Read ”Writing atomic commits” on how to write a good commit history.

3. Provide context to the PR

Include additional context in the PR, such as the link to the JIRA ticket, links to related PRs, and a brief explanation of the implementation. Ideally, your team should have a PR template in the repository that guides the code author to provide this information when creating a PR.

This information allows the reviewer to gain a good understanding of the background before diving into the code.

4. Use draft PR to do a self-review

It is not uncommon to make some obvious mistakes in the PR. For example, you might accidentally push secrets or some temporary changes to the PR. A good practice is to do a self-review before sending it out to your peers. One good way to do this is to use a draft PR.

Once the author thinks everything is ready, you can mark your draft pull request as ready for review, and notification will be sent to the reviewers.

Waiting for feedback

Now that you have sent out the PR, what is next? How fast should we expect to get feedback? Well, it depends on your team culture.

In my current team, we expect team members to review their PR queue first thing in the morning. I can expect receiving a feedback within one working day before I nudge anyone. If the PR stays quiet for more than one working day, you should shout. However, I definitely wouldn’t expect my peers to review my code immediately after I send the PR. After all, distraction is the worst productivity killer for developers. I won’t interrupt my peers unless the PR is really urgent.

If it is urgent, don’t hold back. You have a good reason to nudge the reviewers earlier, but do explain the situation.

Summary

This post discusses practical tips for requesting a code review. As the requester, it’s important to take ownership of the review process and facilitate the work to make it easier for everyone involved to provide feedback.

In the next post, we will explore effective techniques for code reviewers to review and provide feedback.