How to review code and explain why, so the reason is useful

For experts4 min read

A senior engineer typing a written code review on a laptop in a calm Accra home study, a cup of tea and a notebook nearby, soft light

How to review code well is mostly about the written reason. A verdict without evidence helps no one, while a short comment with the problem, the impact and the fix can be checked in a minute. This post gives a structure and a worked example.

How to review code: the three-part comment

Every comment worth leaving has three parts.

  1. What: the exact line or behaviour, in one sentence.
  2. So what: what goes wrong, for whom, and when.
  3. Now what: the fix, or the question that would settle it.

Compare two comments on the same line. Weak: 'This is not safe.' Strong: 'Line 4 runs the command with no timeout. If the program hangs, so does this call, forever. Pass timeout=30 and handle TimeoutExpired.' The second can be acted on without a meeting.

A snippet to review

Python
import subprocess def build(path):    result = subprocess.run(["make", "-C", path], capture_output=True)    return result.stdout

This function runs a build and returns its output. The Python documentation for subprocess.run gives you the facts for the review. The timeout parameter is off by default. When it expires the child process is killed and TimeoutExpired is raised. The check parameter is false by default, and when true a non-zero exit raises CalledProcessError. Without capture text mode, output arrives as bytes.

Source: Python docs: subprocess(opens in a new tab)

Here is a review written with the three parts.

  • No timeout (what). A hung build blocks the caller indefinitely (so what). Add a timeout and decide who handles TimeoutExpired (now what).
  • The exit code is ignored (what). A failed build returns partial output as if it succeeded, and the caller cannot tell (so what). Use check=True, or return the return code with the output (now what).
  • Output is returned as bytes and stderr is dropped (what). Callers get an unreadable value, and the error message that explains the failure is lost (so what). Pass text=True and return stderr as well, or merge it into the output (now what).
Python
import subprocess def build(path):    result = subprocess.run(        ["make", "-C", path],        capture_output=True, text=True, timeout=600, check=True,    )    return result.stdout

This version raises on failure, which moves the decision to the caller. That is a choice. Say so: 'check=True makes build() raise CalledProcessError; confirm the callers expect that.' A reviewer who states the trade-off helps more than one who just rewrites the code.

Severity labels keep a review readable

LabelMeaningExample
Must fixWrong behaviour or a riskIgnores the exit code
Should fixWorks, but fragileNo timeout
NitStyle or tasteVariable name could be clearer
QuestionYou do not know yetDo callers expect an exception?

Mixing a style nit with a data-loss bug in one list hides the bug. Put the serious items first.

A code review checklist you can adapt

  • Correctness: does it do what was asked, on edge cases as well as the example?
  • Failure: what happens on bad input, a slow call or a missing file?
  • Safety: user input in commands, queries or paths; secrets in code.
  • Clarity: could a new teammate follow it?
  • Tests: do they fail when the code is wrong?

Tone and honesty

Write about the code, not the author. 'This loop skips the last item' is a statement about code. 'You forgot the last item' is not. When you are unsure, say what you checked and what you did not. 'I read this but did not run it' is useful information.

Do not invent problems to look thorough. A review of a correct function can say 'No defects found; checked empty and single-item inputs.' A short, accurate review is worth more than a long padded one.

Review code and get paid: how this becomes work

In AI training projects the reasons you write are part of the data. A model learns from a reviewer who explains clearly why one answer is better. Projects also check your reasons against the code, and reasons that contradict the facts are marked down.

Pay is set per job by the client. Practise the structure first on code you know, then take a skill test when your comments come out clean on the first try.

  1. Take one function from your own project and review it as a stranger would.
  2. Write each comment in the what, so what, now what format.
  3. Label each as must fix, should fix, nit or question.
  4. Have a colleague read only your comments and say whether they could fix the code from them.

Curatrain tests engineers at graded levels and matches those who pass to paid, remote projects. Every score is kept.