DEV Community

Cover image for Code reviews people actually read
Mohammad Khalifeh
Mohammad Khalifeh

Posted on Originally published at mkcodestudio.com on

Code reviews people actually read

A code review is useful when the author reads the comments, understands them and changes something. Many reviews fail at the first step: the pull request is too big to review properly, or the comments are too vague to act on. These are the habits that make reviews work for me, on both sides.

As the author

Keep pull requests small. Under about 400 changed lines, reviewers read the code. Above that, they skim it. If a feature is large, split it: the migration first, then the domain change, then the endpoint, then the UI.

Write the description for someone who missed the meeting. What changed, why, and how you tested it. A screenshot for UI changes. A note on anything you were unsure about, so the reviewer knows where to look.

Review your own diff first. Most leftover debug logs, commented-out code and unrelated formatting changes are caught by reading your own pull request before asking anyone else to.

As the reviewer

Separate what blocks from what doesn't. I prefix comments so the author can sort them quickly:

  • blocking: a bug, a security problem, or something that breaks a contract.
  • suggestion: a better approach I would like considered.
  • nit: style or naming. Fine to ignore.
  • question: I don't understand something yet.

Say why, not just what. "Use AsNoTracking() here" is an instruction. "This query only reads, so AsNoTracking() skips change tracking and saves memory on large lists" is something the author can apply next time without you.

Comment on the code, not the person. "This method does three things" lands better than "you made this method too long", and it is more precise.

Approve when it is good enough. A review is not a chance to rewrite the code the way you would have written it. If it is correct, readable and tested, approve it and leave the rest as suggestions.

As a team

  • Automate style. Formatters and linters in CI end most arguments about spacing and naming before a human sees the code.
  • Agree on a response time. A pull request that waits two days goes stale and gets merged with conflicts. Within one working day is a reasonable target.
  • Rotate reviewers. It spreads knowledge of the codebase and stops one person from becoming the bottleneck.

For people learning

When I review code from students or junior developers, I add one more rule: every blocking comment links to a reason, such as a doc page, a test that fails, or an example. The goal of the review is that they need fewer comments next time, and that only happens when they understand the reason behind each one.


Originally published on mkcodestudio.com.

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The blocking / suggestion / nit / question prefixes are the part I would steal first — they make it obvious what actually needs a reply before merging. I am curious about the 400-line limit though: how do you handle a PR that is legitimately big, like a migration or a large refactor that is hard to split without breaking the build? Do you still ask the author to split it, or do you review it differently, for example by walking through it commit by commit?