Dev tools and workflow · Intermediate · 16 min
Review code well, as the author and as the reviewer
By Padding · Updated 18 Nov 2026
Any Git host with pull requests · examples use GitHub, November 2026 · macOS, Windows or Linux
You will have prepared a small pull request for review as its author, then reviewed it as a colleague would, ending with a set of labelled comments and a clear approve or request-changes decision you can reuse on real work.
On this page
A code review has two people in it, and most advice only talks to one of them. The author decides how hard the review will be before anyone else opens it: a 40-line change with a clear reason is quick to review well, and an 800-line change with the description "fixes" gets either a rubber stamp or a week of back and forth. The reviewer then decides whether the conversation stays about the code or turns into a list of personal preferences.
In this tutorial you play both parts on the same small pull request. First, as the author, you review your own diff, write a description that explains why, and point at the part you are least sure of. Then, as the reviewer, you read it in a useful order, check what it does before how it looks, write comments with a clear label, and make a decision. You finish with a note on what to hand to machines (formatters, linters, AI review tools) so that people spend their time on the parts only people can judge.
The sample is on GitHub, but nothing here depends on it. GitLab merge requests, Bitbucket and Gitea work the same way under different button names.
The sample pull request
You work at a small online shop. Prices are stored as whole numbers in kobo (100 kobo is one naira), which avoids rounding errors in money. You have added discount codes at checkout. Here is your change as a diff:
diff --git a/checkout/totals.py b/checkout/totals.py
--- a/checkout/totals.py
+++ b/checkout/totals.py
@@ -1,6 +1,20 @@
+DISCOUNT_CODES = {
+ "WELCOME10": 10,
+ "STAFF50": 50,
+}
+
+
def order_total(items, delivery_fee):
"""Return the order total in kobo (1 naira = 100 kobo)."""
subtotal = 0
for item in items:
subtotal += item["price"] * item["qty"]
return subtotal + delivery_fee
+
+
+def order_total_with_code(items, delivery_fee, code):
+ total = order_total(items, delivery_fee)
+ percent = DISCOUNT_CODES.get(code.upper())
+ if percent:
+ total = total - total * percent / 100
+ return total
diff --git a/tests/test_totals.py b/tests/test_totals.py
--- a/tests/test_totals.py
+++ b/tests/test_totals.py
@@ -1,4 +1,4 @@
-from checkout.totals import order_total
+from checkout.totals import order_total, order_total_with_code
def test_empty_order_costs_only_delivery():
@@ -9,2 +9,7 @@ def test_total_adds_delivery_fee():
items = [{"price": 250000, "qty": 2}]
assert order_total(items, 150000) == 650000
+
+
+def test_welcome_code_takes_ten_percent_off():
+ items = [{"price": 250000, "qty": 2}]
+ assert order_total_with_code(items, 150000, "welcome10") == 585000The test passes. Keep the diff open: every step below refers to it.
Step 1 · Review your own diff before anyone else does
Open the pull request as a draft, or look at the diff in your Git host's "Files changed" view before you ask for review. Reading your change in the same view the reviewer will use catches things your editor hides: a stray debug line, a file you did not mean to commit, a rename that turned into a delete and an add.
Read it once as if a stranger wrote it, and ask three questions:
- Does each line belong to this change? Formatting fixes to unrelated files, a dependency bump or a half-finished idea all go in their own pull request. A reviewer can say yes to one idea at a time.
- What happens with input I did not try? Here: a code typed in lower case (handled by
.upper()), an unknown code (returns the full total), no code at all. If the checkout form sendsNonewhen the box is empty,code.upper()raises an error and the customer cannot pay. That is worth fixing before review, not during it. - Where am I least sure? Here it is the line
total - total * percent / 100. In Python,/always returns a float, so the function now returns585000.0rather than585000. The test still passes because585000.0 == 585000is true, but a 15 per cent code on an odd total would give fractions of a kobo. The discount is also applied to the delivery fee, and you are not sure that is what the business wants.
Fix what you can (guard against an empty code, keep the result a whole number of kobo) and note what you cannot decide alone (does the discount cover delivery?). Size matters too: as a rough guide, if your diff is longer than a reviewer could read carefully in about 20 minutes, split it. Small pull requests also load faster on a phone over mobile data, which matters to reviewers who check work between other tasks on a prepaid bundle.
Check it worked
You have a short list in your notes with at least one change you made after reading your own diff (for example, handling a missing code) and at least one open question you could not answer yourself (whether delivery is discounted). If your list is empty, read the diff again line by line.
Step 2 · Write a description that explains why
The diff shows what changed. The description has to carry everything the diff cannot: why the change exists, how you checked it, and where the risk is. Write it in your notes using these five headings, then paste it into the pull request:
### Why
Marketing wants a 10% welcome code for the November campaign (ticket SHOP-214).
### What changed
- New `order_total_with_code()` in checkout/totals.py, using a fixed list of codes.
- Codes are case-insensitive. Unknown codes, an empty string and a missing
code (None) all return the normal total.
### How I tested it
- New unit test for WELCOME10 on a 6,500 naira order (including delivery).
- Tried an empty string, None and an unknown code by hand in the shell.
### Please look closely at
- The discount is applied to the whole total, including delivery. I could not
confirm whether that is intended. See the comment on line 16.
### Not in this change
- Storing codes in the database and an admin screen for them (SHOP-215).Then leave your own comment on the risky line in the diff, before you request review. Pointing reviewers at the hard part means they spend their attention there instead of on the variable names.
If your repository will see many pull requests, a file at .github/pull_request_template.md pre-fills new descriptions with these headings for everyone.
Write the description in plain, short sentences. On teams that work across several languages, and many teams in Africa do, a reviewer reading in their second or third language will understand "Codes are case-insensitive" faster than a paragraph of context.
Check it worked
Read only your description, not the diff. Can you answer "why does this exist?", "how do I know it works?" and "what should I worry about?" from it alone? Each heading should have at least one concrete line, and "Please look closely at" should name a specific line or decision rather than "everything".
Step 3 · As the reviewer, read the description and tests before the code
Now switch roles. You are the colleague asked to review. For practice, review the diff exactly as first shown at the top of this page, before the author's self-review fixes. That way the None crash and the float result are still there for you to find, and the description's promise about empty codes holds for an empty string "" (an unknown key, so the normal total) but not for None.
Start with the description, then the tests, and only then the implementation.
The description tells you what the author meant to do, so you can judge the code against that intent instead of against your own guess. The tests tell you what the author believes the behaviour is. Reading them first turns the review into a comparison: does the code do what the description and tests say, and do the tests cover what the description promises?
For the sample, write down what you notice before reading totals.py:
- The description promises that unknown, empty and missing (
None) codes return the normal total. There is a test for WELCOME10 only. None of the other promises is tested. - The test compares with
==, which hides the float result (585000.0). An assertion on the type, or on an amount that does not divide evenly, would expose it. - STAFF50 exists in the code but is not mentioned in the description or tested.
Check it worked
Before you open the implementation, your notes have at least two points that came from the description and tests alone. At least one of them should be a promise in the description that no test checks.
Step 4 · Check behaviour before style
Read the implementation with one question first: does it do the right thing for every input it will get? Leave naming, layout and taste for later, and drop them entirely if a tool can enforce them (see the step on automation).
Work through a few cases by hand. You do not need to run anything to do this; a list in your notes is enough, each with the input, what you expect and what the code does. On a 650,000 kobo total:
"WELCOME10": expect 585,000; the code returns 585,000.0, a float."welcome10": the same, thanks to.upper()."NOPE": expect 650,000; the code returns 650,000.None(empty box): expect 650,000; the code crashes onNone.upper()."STAFF50": nobody has said what to expect; the code returns 325,000.0, which takes half the delivery fee off too.
Then look past the function. STAFF50 is a 50 per cent code written in plain text in the source. Anyone who can read the repository, or a future public copy of it, can use it. That is a security and business question, not a style one, and it is more important than anything else in this diff.
Last, ask what is missing: tests for an unknown and an empty code, and a decision on whether delivery is discounted.
Check it worked
Your notes list at least three behaviour points (the None crash, the float result and the staff code in source) and no more than one style point. If most of your points are about names or spacing, go back over your list of cases.
Step 5 · Label every comment and suggest rather than command
A comment without a label leaves the author guessing: is this a must-fix, a question or a passing thought? Start each comment with one of these labels. Many teams use a published scheme such as Conventional Comments; the three below are enough to begin with.
- blocking: this must change before merge. Use it for bugs, security problems and broken promises.
- question: you do not know, and the answer may or may not need a change.
- nit: small polish the author is free to ignore.
You can add praise: for something done well. It costs one line and tells the author what to keep doing.
Write each comment so it says what you see, why it matters and what you suggest. Ask, or propose, rather than order. Compare:
Fix this.
blocking: If the code box is empty the form sendsNone, andcode.upper()raisesAttributeError, so the customer cannot check out. Could we treat a missing code like an unknown one? Something likeDISCOUNT_CODES.get((code or "").upper()), plus a test forNone.
Here is a full set for the sample. Write your own first, then compare:
blocking: STAFF50 gives 50 per cent off and is visible to anyone who can read this repository. Could staff codes live outside the source (configuration or the database in SHOP-215) and be checked against the logged-in user?
blocking:/returns a float, so totals become585000.0, and a 15 per cent code on an odd total gives fractions of a kobo. Suggesttotal - total * percent // 100, and a test that checks the result is anint.
question: The discount includes the delivery fee. Is that what marketing asked for? If not, it should apply to the subtotal only.
nit:order_total_with_codecould takecode=Noneas a default, so callers without a code can keep using one function.
praise: Keeping money in kobo as whole numbers made the arithmetic clear to follow.
On GitHub, a comment can cover several lines, and a suggestion block lets the author apply your proposed change with one click. Use Start a review to collect all your comments and send them together, so the author gets one notification instead of five.
Check it worked
Look at your own comments. Every one starts with a label. Every blocking comment names a concrete failure (an input and what goes wrong), not a preference. At least one comment includes a suggested fix the author could copy. None of them contains "you should have" or "obviously".
Step 6 · Decide: approve when it is better than before
Review tools give you three outcomes. On GitHub they are Comment, Approve and Request changes. Choose by your labels, not by how many comments you left:
- Any blocking comment: request changes, and say what would make you approve.
- Only questions and nits: approve, or comment and approve once the questions are answered. Do not hold a change back for polish.
- Nothing to add: approve, and say what you checked ("Read the tests and tried an empty code; looks good").
The bar is "this leaves the code better than it was", not "this is how I would have written it". A change that fixes a real problem with an imperfect name is worth merging; the name can change later. Waiting for perfect makes authors send fewer, larger pull requests, which are harder to review.
For the sample, the staff code and the float are blocking, so the decision is request changes, with a summary like:
Two blocking points: the staff code in source and the float total. Once those are fixed and there are tests for empty and unknown codes, I'm happy to approve. The delivery question can go to marketing in parallel.
Agree a response time with your team and keep to it. A common target is a first response within one working day. If you cannot review properly in that time, say so and give a time, or suggest someone else. Silence is the slowest kind of review.
Check it worked
Your summary states the decision, lists exactly the blocking points from your comments and nothing else as a condition, and says what would make you approve. Count your blocking comments: if the count is zero, your decision should be approve.
Step 7 · Respond to review as the author
Switch back to the author. You have five comments. Reply to every one, so the reviewer can see each point was read:
- Blocking: fix it in a new commit and reply with what changed ("Moved staff codes out; now checked in
apply_staff_discount()against the user. Test added."). New commits are quicker to re-review than a rewritten history. - Question: answer it. If the answer is "I don't know", say who does and what you will do meanwhile.
- Nit: take it or decline it in one line ("Leaving as is to keep this small; noted for SHOP-215"). Both are fine.
- Disagreement: explain your reasoning once, with evidence. If you still disagree after one round, talk it through on a call. Long comment threads rarely change minds.
Then re-request review. Do not mark a reviewer's blocking thread as resolved yourself unless your team agrees authors may do that; let the person who raised it confirm.
Check it worked
Every comment has a reply from you. Each blocking reply names the commit or the specific change, and each declined nit gives a reason in one sentence. Your new tests include an empty code and an unknown code.
Step 8 · Hand the mechanical checks to tools
Some of the comments a reviewer could leave should never reach a human: indentation, quote style, import order, unused variables, line length. Put them in tools that run before review:
- A formatter (Black or Ruff format for Python, Prettier for JavaScript) settles layout, so nobody argues about it.
- A linter (Ruff, ESLint) catches unused names, shadowed variables and common bug patterns.
- pre-commit hooks and a CI job run both on every change, so the pull request shows a pass or fail before a reviewer looks.
Once those are in place, a style comment from a person means a tool is missing a rule. Add the rule instead of repeating the comment.
AI review tools fit in the same place: as an extra pass, not a reviewer of record. Some, such as GitHub Copilot code review, leave comments without approving unless a repository is set up to let them. Treat each AI comment as a candidate. A person checks whether it is true for this code, keeps the useful ones and dismisses the rest. AI tools can miss the business questions in this sample entirely, such as whether delivery should be discounted, and can state wrong things confidently. The human reviewer still owns the decision.
Check it worked
Go back to your reviewer comments from earlier. Mark any that a formatter or linter could have caught. For each one, write down which tool and rule would catch it next time. If you used an AI review tool on a real change, you have a note next to each of its comments saying whether you kept it and why.
Next steps
Use the same routine on your next real pull request: self-review, a five-heading description, labelled comments and a decision based on blocking points only. Then make the mechanical part automatic:
- Push to GitHub with SSH and open a pull request covers opening the pull request this tutorial reviews.
- Write readable code: names, comments and a formatter helps you write code that needs fewer comments.
- Use AI coding assistants responsibly goes further on checking what AI tools produce.
Related tutorials
- How to Push to GitHub over SSH and Open a Pull RequestYou will connect a local repository to a new GitHub repository over SSH, push your work, push a branch, open a pull request from the website and from the GitHub CLI, merge it, and bring the result back to your computer.
- Write readable code: names, comments and a formatterYou will turn a working but cryptic Python script into a readable one with clear names, named constants, small functions and useful comments, tidy it with Ruff, prove its output has not changed and leave with your own style checklist.
- Use AI coding assistants responsiblyYou will have a one-page policy for using AI coding assistants on your team, covering what goes into a prompt, how generated code and new packages are checked, what an agent may run without asking and who approves anything that deploys.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials