Code review and trade-offs
Turn a vague failure report into a reproduction, isolate the cause, form and falsify hypotheses, instrument the code, fix async and state bugs, lock the fix behind a regression test and review changes for real trade-offs.
What you will be able to do
#- Review a change for correctness, boundaries, performance, security and tests.
- Separate blocking issues from nits and explain the trade-off.
Overview
#A review is a correctness and risk check, not a style contest. The reviewer's job is to find the change that will break in production and to explain the trade-off behind it.
Read the change with three questions. Does it do what it claims? What happens at the boundaries, on empty input, on a missing field, on a failure? What does it cost in complexity, performance and future maintenance?
Separate blocking issues from nits. A blocking issue is a correctness, security or data-loss problem. A nit is a preference. Label them so the author knows what must change and what is optional.
// blocking: the token is logged, leaking a credential
logger.info({ token }, 'auth attempt');
// fixed: log an identifier, never the secret
logger.info({ userId }, 'auth attempt');
Look for the missing case more than the wrong line. Most production bugs are not typos; they are unhandled states. Ask what happens when the list is empty, the request fails, or the user double-clicks.
async function submit(form) {
if (submitting) return; // guards the double submit
submitting = true;
try {
await save(form);
} finally {
submitting = false;
}
}
When you suggest a change, give the reason and the alternative. Use a Map here is weaker than a Map keeps lookups O(1) as this list grows, while an array scan is O(n) per render. The trade-off is the review.
Finally, review the tests in the same change. A fix without a test is a fix that will regress. A test that asserts the wrong thing is worse than no test, because it gives false confidence.
Exercises
#Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.
Exercise 1Interview
You are reviewing a pull request that adds a search box. List the questions you would ask about correctness, boundaries, performance and tests.
Reveal the reference answer
reference.textCorrectness: does it debounce input and cancel stale requests? Boundaries: what happens on empty input, a failed request and a very long query? Performance: how many requests per keystroke, and does the result list re-render on every character? Tests: is there a test for the empty result, the error state and the stale-response guard? I would also check that any logged value contains no secrets.Authored expected output: Questions grouped by correctness, boundaries, performance and tests, plus a security check on logged values.
Grouping the questions keeps the review systematic: correctness covers the happy path, boundaries cover empty and failure states, performance covers request and render cost, and tests cover the guard rails. The security check catches secrets in logs.
Exercise 2Explain
Explain the difference between a blocking review comment and a nit.
Reveal the reference answer
reference.textA blocking comment names a correctness, security or data-loss problem that must be fixed before merge. A nit is a preference that does not affect behaviour and is optional. Labelling them separately lets the author act on what matters and ignore what does not.Authored expected output: An explanation that blocking means correctness, security or data loss, while a nit is optional preference.
Labelling the severity lets the author act on what matters and ignore what does not. Blocking comments name a real risk; nits are preferences that do not change behaviour.
Common misconceptions
#- Every style preference is a blocking review comment.
- A change with passing tests does not need a boundary review.
Follow-up practice
#- debugging-review-12-concurrency-and-races
Your progress
#Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.
Verification: authored. Answers and outputs on this page are authored reference material, not executed results.