home / Advanced / Giving and Receiving Code Review

Giving and Receiving Code Review

level: advanced · difficulty 3/3 · published 2026-10-02

The core idea

Code review is a structured conversation about a proposed change to a codebase. It is not a gatekeeping ritual or a test of personal worth; it is a technical practice where one or more people examine a diff, ask questions, and suggest improvements before the change is merged. The core idea is that code quality is a shared responsibility, and the best way to improve it is through frequent, small, focused reviews. A review typically covers correctness, readability, maintainability, performance, security, and adherence to team conventions. The reviewer's job is to understand the intent, verify the implementation, and communicate clearly. The author's job is to make the change easy to review and to respond constructively. Both roles require empathy and precision. The goal is not to find fault but to collectively raise the quality of the system and to spread knowledge across the team. When done well, code review becomes a learning loop: authors learn from feedback, reviewers learn from reading unfamiliar code, and the codebase becomes more consistent and robust.

Why it matters at scale

As a codebase and team grow, the cost of defects and inconsistencies rises superlinearly. A single misunderstood interface can cascade into hours of debugging across multiple services. Code review catches many of these issues before they reach production, but its value at scale goes beyond bug detection. It enforces architectural boundaries, ensures that logging and error handling are uniform, and prevents the accumulation of small hacks that eventually become unmaintainable. It also serves as a distributed onboarding mechanism: new engineers learn conventions by reviewing and being reviewed. Without review, knowledge silos form, and only the original author understands a module. With review, at least two people have seen every change, which reduces bus factor and makes refactoring safer. Moreover, review is one of the few practices that directly addresses the social aspects of software engineering: it builds trust, establishes shared standards, and creates a culture where feedback is normal and expected. At scale, these social benefits compound, making the team more resilient and the codebase more coherent.

How it works

The mechanics vary by tool, but the general flow is consistent. An author creates a branch, makes a focused change, and opens a pull request or merge request. The diff is displayed, often with inline commenting. Reviewers read the diff, leave comments, and either approve, request changes, or comment without blocking. The author addresses feedback by pushing new commits, which updates the diff. Discussion continues until consensus is reached, then the change is merged. Effective reviews are small: a few hundred lines at most. Large diffs overwhelm reviewers and lead to shallow approvals. Reviewers should prioritize correctness and design over style, which can be automated with linters and formatters. Comments should be specific, actionable, and kind. For example, instead of "this is wrong," say "this will throw if input is null; consider adding a guard clause." Authors should respond to every comment, either by making a change or explaining why not. Tools like GitHub, GitLab, and Gerrit support this workflow, but the principles apply regardless of platform. The key is to keep the loop tight and the tone professional.

A worked example

Suppose you are reviewing a Python function that calculates the average of a list of numbers. The original code is:

def average(nums):
    return sum(nums) / len(nums)

A reviewer might note that this raises ZeroDivisionError for an empty list and that nums could be a generator, which len() does not support. A revised version could be:

def average(nums):
    nums = list(nums)
    if not nums:
        raise ValueError("average() arg is an empty sequence")
    return sum(nums) / len(nums)

This example illustrates several review principles. The comment is specific: it names the exception and the condition. The suggestion is actionable: convert to a list and check for emptiness. The author can then respond, perhaps noting that the caller already guarantees a non-empty list, in which case the guard might be unnecessary. The discussion stays focused on the code, not the person. The final merged version is more robust and documents the assumption. In a real review, you might also discuss whether to use statistics.mean from the standard library, which handles some edge cases, but that is a separate design decision. The point is that a small, concrete suggestion improves the code and teaches both parties something about Python's behavior.

Trade-offs and pitfalls

Code review is not free. It adds latency to the development process, and if overdone, it can become a bottleneck. Requiring multiple approvals for every trivial change can frustrate authors and slow delivery. There is also a risk of review becoming performative: reviewers may focus on nitpicks like spacing while missing architectural flaws. Another pitfall is the "rubber stamp" review, where a reviewer approves without truly reading the diff, which provides false confidence. On the author side, defensiveness can turn a technical discussion into a personal conflict. To mitigate these, teams should agree on what must be reviewed (e.g., all changes to production code) and what can be automated (formatting, linting). They should also set expectations for response times and encourage authors to self-review before requesting others. Some teams use pair programming as an alternative or complement to asynchronous review, which can catch issues earlier and reduce the need for lengthy comment threads. Ultimately, the trade-off is between speed and quality; the right balance depends on the criticality of the system and the maturity of the team.

How to apply it

Start by making reviews small and frequent. Aim for pull requests that take less than 30 minutes to review. Before requesting review, run the tests and linters locally, and write a clear description that explains the what and the why. As a reviewer, read the description first, then the diff. Ask questions rather than making demands. Use a prefix like "nit:" for minor style suggestions so the author knows they are optional. Approve when the change is an improvement, even if it is not perfect; perfect is the enemy of done. As an author, respond to every comment, and if you disagree, explain your reasoning with evidence. If a discussion becomes heated, switch to a synchronous call. Over time, build a team charter that defines review expectations, such as required approvals, turnaround time, and what constitutes a blocking issue. Rotate reviewers to spread knowledge. Finally, measure the process: track how long reviews take and how many comments lead to changes. Use that data to improve, not to blame. The goal is a sustainable practice that improves both the code and the team's communication skills.

Frequently asked questions

How do I handle a reviewer who is overly nitpicky? First, distinguish between blocking issues and preferences. If a comment is about style, it can often be resolved by adopting a shared formatter like Black for Python or Prettier for JavaScript, which removes subjective debates. If the reviewer continues to block on non-critical points, discuss it with them privately or bring it up in a team retrospective. What if I disagree with a review comment? Respond respectfully with your reasoning, and if needed, ask a third person to weigh in. Remember that the goal is the best outcome for the codebase, not winning an argument. How long should a review take? There is no universal rule, but many teams aim for a first response within a few hours and a full review within one business day. If reviews consistently take longer, consider reducing the size of changes or adding more reviewers. Can I review my own code? Yes, self-review before requesting others is a best practice; it catches obvious mistakes and shows respect for reviewers' time. Ultimately, code review is a skill that improves with practice and feedback.