Essay

Code Review as Teaching

A review comment can fix one line or change how someone thinks. How to write comments that explain the why and leave the author stronger next time.

Swati S.12 min read

TL;DR: Code review is knowledge transfer. Explain the why behind each comment, point to patterns, suggest alternatives, and review design as well as syntax. Keep reviews a conversation, and measure their quality by what people learn, not only by the bugs you catch.

Two lanes compared: a review that only judges ends with the same mistake next week, while a review that teaches moves from comment to reason to example to next step and ends with the author owning the pattern
A comment that gives a reason, an example, and a next step turns a one-line fix into a pattern the author keeps.

Code review is not quality control. It's knowledge transfer. Every comment is a teaching moment. Every approval is a lesson. The code you review today becomes the code someone else writes tomorrow.

I've seen teams where code reviews were weapons. Engineers left comments like "this is wrong" without explanation. The result? Newer engineers learned to fear reviews, not learn from them. They'd make the minimal change to get approval, not improve their understanding.

The best code reviews I've received weren't about catching bugs—they were about teaching thinking. The reviewer explained why a change mattered, what edge cases I'd missed, what patterns I could apply elsewhere. I learned more from those reviews than from any tutorial.

Start from a place of curiosity. "I see you did X. Help me understand why." Assume good intent. Assume they know something you don't. Your job is to understand, then guide.

A scene to hold on to

Picture a pull request that adds a "recent orders" endpoint. It loops over twenty orders and runs one database query per order to fetch the customer. The tests pass. The reviewer leaves one comment: "N+1 here." The author adds a join, resubmits, and gets approved.

Nothing is wrong with that review, and nothing was taught. Three weeks later the same author writes a "recent invoices" endpoint with the same loop. The reviewer fixes it again. That is the cost of a review that only judges.

Now picture the other version. The comment says: "This runs one query per order, so twenty orders means twenty-one round trips. At 5 ms each that is 100 ms before any real work, and it grows with the page size. Fetch the customers in one query and map them by ID. Here is the pattern we used in the cart service. Next time you loop over rows and call the database inside the loop, stop and check for this." The fix is the same. The author's next endpoint is different. The production version of this story is in the N+1 query crisis.

The four-part comment

Here is the habit I'd practice this week. Every comment that matters gets four parts:

  1. Comment. What you noticed, in one sentence.
  2. Reason. What will break, or what it costs, or what it teaches others to copy.
  3. Example. A snippet, a link to existing code, or a past incident.
  4. Next step. What you'd do, and whether it is blocking.

You will not use all four on a typo. Use them on anything you'd be annoyed to say twice. The picture at the top shows the difference: the review that only judges has two steps and ends in the same mistake next week. The one that teaches has four and ends with the author owning the pattern.

Explain the why, not just the what

Don't just say "this is wrong." Explain why it's wrong. What will break? What edge case will fail? What pattern will it encourage others to copy?

# Instead of: "Use a dictionary here"
# Say: "A dictionary gives O(1) lookups. With 1000 items, this list 
# search will be O(n) and could become a bottleneck. If this grows 
# to 10,000 items, it will be slow. Use a dictionary for constant-time lookups."

# Bad
items = [item for item in items if item.id == target_id]

# Better
items_dict = {item.id: item for item in items}
target = items_dict.get(target_id)

The first comment fixes one line. The second comment prevents a class of mistakes. It teaches performance thinking, not just syntax.

I once left a comment that just said "use a set instead of a list." The engineer changed it, but they didn't understand why. The next week, they made the same mistake in a different place. If I had explained why sets have O(1) membership checks while lists have O(n), they would have understood the pattern, not just memorized the fix.

A quick test before you post: could the author explain your comment to someone else? If the comment only works because they trust you, it will not travel to the next file.

Point to patterns, not just problems

When you see a problem, ask: "Does this pattern exist elsewhere?" Don't just fix the instance. Fix the pattern. Document it. Share it in team notes.

If you find the same issue in three places, that's a pattern. Patterns need pattern solutions: a helper function, a shared component, a design guideline.

I once reviewed code that used string concatenation for building URLs in five different places. Instead of fixing each instance, I suggested a helper function. The next week, two engineers used that helper function in new code. The pattern solution taught the pattern. That is the DRY principle in practice, with one warning: wait for the third copy before you extract. Two copies can still be a coincidence.

Patterns also need pattern prevention. When you see a common mistake, document it. Add it to your team's "common pitfalls" list. Share it in a team meeting. Help others avoid it before they make it. A linter rule or a test is even better than a document, because it teaches at the moment the mistake is typed.

Review architecture, not just syntax

Syntactic errors are easy to catch. Architectural problems are harder. Ask:

  • Does this fit the existing patterns?
  • Will this scale with our expected growth?
  • What happens when we need to change this?
  • Does this create coupling we'll regret later?

These questions teach thinking, not just coding.

I once reviewed code that solved the immediate problem but created tight coupling. I asked: "What if we need to change the data source?" The engineer said: "We'll change it then." I asked: "How many places would you need to change?" They counted: seven. That question taught them to think about future flexibility, not just current correctness.

Architectural reviews are harder because they require judgment, not just knowledge. But they're more valuable because they teach judgment, not just syntax. The usual lens here is separation of concerns: if a change to storage forces edits in seven files, the concerns were not separated.

Suggest alternatives, don't just reject

Instead of "this won't work," say "here's another approach." Offer options. Explain trade-offs. Let them choose, but make the choice informed.

Say a pull request sends confirmation emails inside the request handler. You could write "move this out." A better comment lays out the options, using ideas the author can look up: a message queue, a database table polled by a worker, or a cache of pending sends.

# Current approach (works, but might be slow for high volume)
# Alternative 1: Use a queue (better for high volume, adds complexity)
# Alternative 2: Use a database (better for persistence, adds latency)
# Alternative 3: Use a cache (better for speed, loses data on restart)
# 
# For this use case, I'd recommend Alternative 1 because we expect 
# high volume and can tolerate added complexity.

Teaching means giving tools, not just answers. When you suggest alternatives, you teach trade-off thinking, not just syntax.

Notice the last line of that snippet. You can recommend one option and still leave the decision open. If the author picks Alternative 2 and gives a reason, accept it. They have practiced the skill you were trying to teach, and that matters more than your preferred answer. If you want to practice laying out options like this, the trade-off thinking article is a good place to start.

Celebrate good patterns

Not all reviews are corrections. When you see good code, say why it's good. "I like how you handled the edge case here." "This abstraction will make testing easier." "This pattern will scale well."

Positive feedback reinforces good practices. It also builds trust. Reviews shouldn't feel like criticism. They should feel like collaboration.

I make it a point to leave at least one positive comment in every review. Even if the code needs significant changes, find something good. It could be clear naming, good error handling, or thoughtful comments. Positive feedback makes critical feedback easier to accept.

Be specific. "Nice work!" teaches nothing. "Naming this retry_after_seconds instead of delay made the call site readable" tells the author what to repeat. Praise with a reason is the same skill as criticism with a reason.

Review in context

Understand what the change is trying to accomplish. A hack in a hotfix is different from a hack in a feature. A quick solution to unblock testing is different from production code.

Provide feedback that fits the context. Emergency fixes get different standards than new features. Teaching means knowing when rules apply and when they don't.

I once reviewed an emergency hotfix where the engineer used a quick workaround. I could have suggested a cleaner solution, but the context was: users are down, we need a fix now. I approved the workaround and suggested we file a ticket to refactor it later. Teaching means understanding context, not just applying rules.

The ticket matters. Approving a shortcut without recording it is how technical debt piles up unseen. Say it in the review: "Approved for the incident. Follow-up filed as ticket 412, due next sprint." The author learns that shortcuts are allowed, and that they are tracked.

Make reviews a conversation

The best reviews happen in dialogue. Ask questions. Listen to answers. Iterate on solutions. Don't just leave comments and walk away. Engage.

I've had reviews where we went back and forth four times, each iteration improving the solution. By the end, both of us learned something. The engineer learned about the pattern. I learned about their reasoning. Good reviews are conversations, not monologues.

When a thread goes past two rounds of back and forth on the same point, stop typing and talk for five minutes. A call settles in minutes what comments settle in a day. Then write the outcome back in the thread so the next reader can see the reasoning.

Review the design, not just the implementation

Code review isn't just about the code—it's about the design. Ask:

  • Is this the right solution to the problem?
  • Are there simpler alternatives?
  • Does this create technical debt?
  • Will this be maintainable in six months?

These questions teach design thinking, not just implementation skills.

I once reviewed code that solved a problem correctly, but in a complex way. I asked: "What problem are you trying to solve?" They explained. I asked: "Could we solve it more simply?" They thought about it. The next iteration was much simpler. The question taught them to think about simplicity, not just correctness.

The earlier section was about fit and coupling inside the codebase. This one is about the choice itself: should this feature exist in this shape at all? Principles like KISS and YAGNI give you shared words for that question. Ask it early, ideally on a design note before the code is written, since a late "should we build this?" costs the author the most.

Use reviews to teach judgment

Code review is where judgment gets developed. When should you optimize? When should you keep it simple? When should you add abstraction? When should you avoid it?

These aren't questions with right answers—they're questions of judgment. Good code reviews help develop that judgment by explaining the reasoning behind recommendations.

I try to explain my reasoning in reviews. "I'm suggesting this pattern because we'll likely need to extend it later." "I'm avoiding this abstraction because it's premature." Those explanations teach judgment, not just rules.

Judgment grows from seeing the same trade-off in different settings. A review that says "cache this" on Monday and "don't cache this, it changes too fast" on Thursday is not inconsistent. It is showing the author the question behind both answers, which is how often the data changes. Caching strategies covers that question in depth.

Review with empathy

Remember what it's like to be on the receiving end. Put yourself in their shoes. How would you want feedback? What would help you learn?

I try to frame comments as questions when possible. "Have you considered X?" instead of "You should do X." Questions invite dialogue. Commands invite defensiveness.

Also, recognize that everyone makes mistakes. A code review isn't a judgment of character—it's a learning opportunity. Treat it that way.

One caution. A question is not a way to hide an instruction. "Have you considered using a lock here?" when you know the code races is a polite order, and authors can tell. If it must change, say so and say why. Use questions when you want their reasoning, and statements when you have a requirement. Asking good questions is a skill worth practicing on its own.

Measure review quality by learning

Good code reviews result in better code, yes. But they also result in better engineers. The newer engineer who learns from your review will write better code next time. The experienced engineer who learns from your review will review better code next time.

Measure review quality by what people learn, not just by what bugs you catch. If engineers are making the same mistakes after your reviews, your reviews aren't teaching effectively.

Code review is teaching. Teaching requires patience, clarity, and empathy. Review the code, but teach the engineer. That's how teams get better.

If you want a related habit from the other side of the table, The Art of Reading Production Code covers how to read a change in context, and On Cultivating Debugging Sense covers what to do when the bug you flagged shows up in production.

Try this week

Take your next three reviews and do the following:

  1. Write every non-trivial comment in four parts: comment, reason, example, next step.
  2. Prefix each comment with "Blocking:" or "Optional:".
  3. Leave one specific compliment per review.
  4. At the end of the week, search your own past comments for any you wrote twice. Those are patterns. Write the helper, test, or team note that makes the third one unnecessary.

The result you want is the same comment never appearing again.

Frequently asked questions

How do I give feedback that teaches, not just corrects?
Explain why: what will break, what edge case, what pattern it encourages. Offer options and trade-offs—'Here's another approach' instead of 'this won't work.' Ask questions. Frame comments as questions when possible. Start from curiosity: 'I see you did X. Help me understand why.'
What should I focus on in code review?
Review architecture and design, not just implementation. Ask: Does this fit? Will it scale? What happens when we need to change it? Is this the right solution? Point to patterns that exist elsewhere; fix the pattern, document it, share it.
How do I make code reviews less intimidating?
Assume good intent. Celebrate good patterns. Make it a conversation. Measure review quality by what people learn, not just by bugs caught. The code you review today becomes the code someone else writes tomorrow—every comment is a teaching moment.
How do I tell a blocking comment from a suggestion?
Label it. Start with "Blocking:" for anything that breaks correctness, security, or data, and "Optional:" or "Nit:" for taste. Authors waste hours guessing which comments are required. A label costs you two words and removes the guessing.
What if the author ignores my comment or pushes back?
Treat pushback as information. Either they know something you don't, or your comment did not explain the reason well enough. Ask what they were optimizing for. If the risk is real, show a failing case or link to a past incident. Not every disagreement needs to be won; save blocking for things that hurt users or the team later.
How do I review code written with AI help?
Review it as if a teammate wrote it, and ask the author to explain any block they cannot walk through. The risk is code that passes tests but nobody understands. How to Actually Learn From AI-Generated Code covers how authors can use AI output as a learning tool instead of a shortcut.
How long should a review take?
Small pull requests, under about 300 lines, deserve a same-day response and 15 to 30 minutes of attention. Large ones should be split. A review that sits for three days teaches the author to avoid asking, which is the opposite of the goal. If you cannot review today, say when you can.
How do I get better at spotting design problems in review?
Read more production code before you review it. Knowing how requests flow through a system makes coupling and missing edge cases easier to see. The Art of Reading Production Code lays out a path for that. Then practice on design problems where you critique a class layout before writing it.

About the author

Swati S. helps you master system design with patience. We believe in curiosity-led engineering, reflective writing, and designing systems that make future changes feel calm.

Ask about this page

No signup needed · Sign in to save your plan