How to review a code change
A diff shows what changed. Deciding whether the change is right is still your job. This routine works for a copied function, a small script or a configuration change.
Start with the purpose
Write one sentence that says why the code changed, for example "Normalize license codes before validation". Then read every changed row against that sentence. A bug fix should touch only the area of the bug. If a wording change also touches database access, permissions or file handling, review that part on its own.
What each kind of row can hide
- Added rows bring new logic, a new branch or a new dependency.
- Deleted rows may remove dead code, or they may remove a safety check, a message or a setting that other code relies on.
- Modified rows need the closest reading. A renamed variable is safe only if every reference was renamed. A changed condition is safe only if both the true case and the false case still behave correctly.
Worked example
Open Compare Codes and click Sample. It loads two versions of a small C# license validator and reports 4 modified rows and 1 deleted row in 3 blocks. Read them against the purpose "Normalize license codes before validation".
Block 1: empty input
return false; became throw new ArgumentException("License code is required.");. This has nothing to do with normalizing. Every caller that expected false for an empty field now gets an exception.
Block 2: the format check
The old code required exactly four parts separated by dashes. The new code only checks that a dash exists, so ABCD-EFGHIJKLMNOPQR was rejected before and is accepted now. The tool pairs rows in order, which puts Split('-') next to the unrelated Contains("-"), so read this block as a whole. Only ToUpperInvariant() matches the stated purpose.
Block 3: the return value
The added normalized.Contains("-") repeats a check that already ran a few lines above. It is harmless, but it suggests the author was unsure about the earlier change.
Result: one change matches the purpose, two change behavior without saying so, and one is redundant. Reading every block matters more than counting rows.
Checklist
Review the risky areas first. A one line change there can cause a security issue or data loss:
- Input validation, authentication and permission checks
- Database queries and filters
- Payments, subscriptions and anything that deletes data
- File paths, uploads, external URLs and API calls
- Error messages that could expose private details
Then check behavior, not only text:
- Run the code with a normal input, and with empty, too long, invalid and duplicate input.
- Follow the failure path. The user should get a clear message, and nothing private should leak.
- In Python, YAML and Makefiles, review once with whitespace visible. Indentation is part of the code there. See whitespace in diffs.
- Keep comments that explain a business rule or an unusual choice. Remove comments that describe code that no longer exists.
For code from an AI assistant or a forum, add the extra steps in how to review copied code.