📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What makes a good pull request? Talk me through size, the description, tests and self-review, and why each one matters to the people reviewing it.

Covers the four habits of a reviewable pull request: small focused size, a description that explains why, tests that prove the change, and a self-review before asking anyone else.

Junior Theory Beginner code-quality code-review engineering-practice git pull-requests testing

🎯 Key points

  • Small and single-purpose: roughly under 400 changed lines, one reason to change
  • Refactoring and behaviour changes in separate commits or PRs
  • Description says why, what changed, how it was tested, and the risk
  • Link the work item; screenshots or sample requests for visible changes
  • Tests in the same PR prove the behaviour, and CI is green before review
  • Self-review the diff first: debug code, commented-out code, secrets, stray files
  • Draft PRs for early feedback; stacked PRs for large features
  • Respond to every comment and keep the conversation in the PR

⏱ 30-second answer

A good pull request is one a reviewer can understand, verify and approve in one sitting.

  • Size: small and focused on one change, ideally under about 400 changed lines. Review quality drops sharply on large diffs, so split refactoring from behaviour change.
  • Description: explain why, not just what: the problem, the approach, how you tested it and any risk or rollout step. Link the work item.
  • Tests: include tests that prove the new behaviour, and make sure CI is green before you ask for review.
  • Self-review: read your own diff in the PR tool first and remove debug code, commented-out code and unrelated changes.

The trade-off: splitting work into small PRs costs the author a little planning time, but it saves reviewers far more and gets the change merged sooner.

🗣 Full answer (senior)

How I would answer this in an interview

"A good pull request is one a reviewer can understand, check and approve in one sitting, so I optimise for the reviewer's time. The first thing is size. I keep a PR to one purpose, usually under about 400 changed lines, because studies of code review and my own experience both show that defect-finding drops off badly after that: people skim a 2,000-line diff and approve it. If I renamed a class and also changed pricing logic, that's two PRs, or at least two commits, so the rename doesn't hide the real change.

The second thing is the description. The diff already shows what changed; the description has to say why. I write the problem, the approach and the alternatives I rejected, how I tested it, and anything risky like a migration or a feature flag. I link the ticket, and for UI or API changes I add a screenshot or a sample request and response. Then tests: the PR includes the tests that prove the behaviour, and CI is green before I request review, because asking someone to review red code wastes their time.

Finally, self-review. Before I add reviewers I read my own diff in the PR tool, top to bottom, as if someone else wrote it. I nearly always find something: a leftover Console.WriteLine, a commented-out block, a file I didn't mean to commit, a vague name. The mistake I see is people treating review as the place to find their own sloppiness. A PR should be a request for a second opinion, not a request for someone to finish your work."


The four parts of a good PR

Part What good looks like Why it matters
Size One purpose, ~50–400 changed lines Reviewers find more defects in small diffs and respond faster
Description Why, what, how tested, risk, ticket link The reviewer can judge the approach, not just the syntax
Tests New behaviour covered; CI green Proof the change works; protects it from the next change
Self-review Diff read once by the author first Catches the cheap problems before they cost someone else's time

A description template

Section Example
Why Invoices for GST-free items were taxed at 10% (bug #1423)
What TaxCalculator now reads the item's tax code; added TaxCode.GstFree
How tested Unit tests for each tax code; ran the invoice export against the test tenant
Risk / rollout No migration. Behind invoice-tax-codes flag, off by default

Ways to keep PRs small

Technique When it fits
Separate refactoring PR first You need to reshape code before the real change
Feature flag The feature is too big for one PR but each slice can merge safely
Stacked PRs Changes depend on each other; each is reviewed on its own
Draft PR You want early feedback on the approach before polishing

Production example

On a team of eight, PRs averaged about 900 changed lines and took around three days to merge. After agreeing on a soft 400-line limit and a description template, the median dropped to about 180 lines and time to merge fell to under a day, with fewer post-merge bug fixes because reviewers were actually reading the diffs.

🔍 What the interviewer is checking

Checks whether the candidate thinks about the reviewer and the team, not just about getting their own code merged.

Green flags

  • Gives a concrete size guideline and explains why size affects review quality
  • Says the description explains why, with test evidence and risk
  • Mentions self-review and green CI before requesting review
  • Separates refactoring from behaviour change

Red flags

  • "The reviewer can just read the code"
  • Treats tests as optional or a later task
  • No idea how to split a large feature

📚 Learn in depth

1. Why size dominates review quality

Review is a human reading task with limited attention. Research on code review at large companies (Cisco's SmartBear study is the classic one) found that reviewers find most defects in the first 200–400 lines and the first hour; past that, the defect-detection rate falls off. A large diff also hides risky lines among trivial ones.

Changed lines   Typical reviewer behaviour
   < 100        reads every line, asks questions
 100 - 400      reads carefully, maybe in two passes
 400 - 1000     skims, focuses on files they know
   > 1000       "LGTM" after scrolling

2. What a reviewer needs that the diff can't give

The diff shows lines; it doesn't show intent, rejected alternatives, test evidence or rollout risk. Without those, reviewers either guess or ask, and every question costs a round trip (often hours across time zones). A good description front-loads the answers.

3. Separating refactoring from behaviour change

A rename across 40 files plus a two-line logic change produces a 300-line diff where the two important lines are invisible. Split it:

PR 1: Rename OrderSvc -> OrderService   (mechanical, approved quickly)
PR 2: Fix discount rounding             (12 lines, reviewed carefully)

If you can't split into PRs, split into commits and say "review commit by commit" in the description.

4. Tests as part of the change

Tests belong in the same PR as the behaviour. They prove the change works today and stop the next change from silently breaking it. Reviewers can read the tests first as an executable specification.

5. Self-review in the PR tool

Reading your diff in GitHub or Azure DevOps (not your IDE) shows you exactly what the reviewer sees. Common catches: debug output, // TODO notes you meant to resolve, secrets in appsettings.Development.json, generated files, unrelated whitespace churn from a different formatter.

6. Automation that keeps humans for judgement

Let tools handle style and simple rules: dotnet format --verify-no-changes, analysers with warnings as errors, a PR template, and branch protection that requires green CI. Humans then spend their review on design, correctness and naming.

Try it yourself

  1. Take your last merged PR and count changed lines. Could it have been two PRs?
  2. Write a PR template in .github/pull_request_template.md with Why / What / How tested / Risk.
  3. Before your next review request, read the diff in the browser and note everything you change.
  4. Run git log --stat on a feature branch and split one mixed commit with git add -p.
  5. Add dotnet format --verify-no-changes to CI so formatting never appears in review comments.

💻 Code

A PR template the team keeps in the repository, so every description answers the same questions.

<!-- .github/pull_request_template.md -->
## Why
<!-- The problem or ticket. Link it: AB#1423 -->

## What changed
<!-- The approach, and any alternative you rejected -->

## How I tested it
- [ ] Unit tests added or updated
- [ ] Ran locally against the test tenant

## Risk and rollout
<!-- Migration? Feature flag? Anything to watch after deploy? -->

## Self-review
- [ ] I read my own diff in the browser
- [ ] No debug code, commented-out code or unrelated changes

A small, focused change with its test in the same PR (before and after):

// Before: GST applied to every line, including GST-free items.
namespace Billing;

public sealed class TaxCalculator
{
    public decimal TaxFor(InvoiceLine line) => Math.Round(line.Net * 0.10m, 2);
}
// After: the tax code decides the rate. One reason to change, one test file.
namespace Billing;

public enum TaxCode { Standard, GstFree }

public sealed record InvoiceLine(string Sku, decimal Net, TaxCode TaxCode);

public sealed class TaxCalculator
{
    private const decimal GstRate = 0.10m;

    public decimal TaxFor(InvoiceLine line) => line.TaxCode switch
    {
        TaxCode.GstFree => 0m,
        _ => Math.Round(line.Net * GstRate, 2, MidpointRounding.AwayFromZero)
    };
}

public sealed class TaxCalculatorTests
{
    [Theory]
    [InlineData(TaxCode.Standard, 100.00, 10.00)]
    [InlineData(TaxCode.GstFree, 100.00, 0.00)]
    public void Tax_depends_on_tax_code(TaxCode code, decimal net, decimal expected) =>
        Assert.Equal(expected, new TaxCalculator().TaxFor(new InvoiceLine("SKU-1", net, code)));
}

⚠ Common mistakes

  • Mistake: Bundling a large rename or reformat with a behaviour change. Why it is wrong: The important lines disappear in the noise and reviewers miss them. Instead: Put the mechanical change in its own PR or commit first.
  • Mistake: A description that just repeats the branch name, like "Fix bug". Why it is wrong: The reviewer can't judge whether the approach is right without knowing the problem. Instead: Write why, what, how tested and the risk.
  • Mistake: Requesting review while CI is red. Why it is wrong: The reviewer may review code that will change, wasting their time. Instead: Get CI green first, or open a draft PR and say what feedback you want.
  • Mistake: Leaving tests for a follow-up PR. Why it is wrong: The follow-up often never happens, and the reviewer has no proof the change works. Instead: Ship tests with the behaviour.
  • Mistake: Skipping self-review. Why it is wrong: Reviewers spend their attention on debug code and typos instead of design. Instead: Read your own diff in the PR tool before asking anyone.
  • Mistake: Force-pushing over review comments mid-review. Why it is wrong: Reviewers lose track of what changed since they last looked. Instead: Add fix-up commits during review and squash on merge.

🏛 Senior insight: trade-offs

Small PRs are a team habit, not a personal virtue. They only work if the codebase supports merging incomplete work safely (feature flags, trunk-based development, fast CI). A senior engineer makes that possible, then models it: splitting their own work visibly and saying "this is PR 2 of 4" in the description.

Option When it fits Cost When not to
One PR per feature Tiny features Low Anything over ~400 lines
Stacked PRs Dependent slices Rebase overhead Tooling doesn't support it well
Feature flag + small PRs Long-running features Flag cleanup later Trivial changes
Draft PR Approach is uncertain Reviewer time early The design is already agreed

Measure it: median PR size, time to first review and time to merge (GitHub Insights, Azure DevOps analytics or a simple script over the API).

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions small PRs merged often or short-lived branches. Why: Checks whether they understand the branching model that makes small PRs practical.
    How to answer

    Git Flow keeps two long-lived branches, main (released code) and develop (next release), plus feature/*, release/* and hotfix/* branches that merge back in a set order. Trunk-based development has one long-lived branch, main; developers branch for hours or a day or two, open a small pull request and merge behind CI checks, using feature flags to hide unfinished work.

    Most teams moved to trunk-based because long-lived branches delay integration: the longer a branch lives, the bigger the merge and the later you find that two changes conflict. Short branches keep main always releasable, which is what continuous delivery needs.

    The trade-off: trunk-based asks for good automated tests and flag discipline; Git Flow still suits products that ship numbered versions and patch several releases at once.

  2. When: Candidate mentions separating refactoring from behaviour changes. Why: Checks they know what refactoring is and how to keep it safe with tests.
    How to answer

    Refactoring is changing the internal structure of code without changing its observable behaviour, in small, reversible steps, so it becomes easier to understand and cheaper to change. It is not a rewrite, a bug fix or a new feature: if outputs, side effects or the public contract change, it is no longer a refactoring, and it belongs in a separate commit.

    You need tests first because they are the only cheap proof that behaviour didn't change. Where there are none, write characterisation tests that pin down what the code does today, bugs included. Then work in tiny steps: one named refactoring (rename, extract method, move), run the tests, commit.

    The trade-off: refactoring spends time now to buy speed later, so do it where you are about to change code, not across the whole codebase.

  3. When: Candidate mentions how reviewers should respond to their PR. Why: Checks they understand the reviewer's side: priorities, tone and blocking versus suggestion.
    How to answer

    Good review is about finding real problems and sharing knowledge without slowing the team.

    • What I look for, in order: correctness and edge cases, security and data handling, design and fit with the codebase, tests, then readability and naming. Style is the analyser's job, not mine.
    • How I word it: about the code, not the person, with the reason: "This query runs once per order line, so 500 lines means 500 round trips. Could we load them in one query?"
    • Blocking vs suggestion: I label every comment (blocking, suggestion, nit, question) so the author knows what must change before merge.
    • Receiving: assume good intent, answer every comment, and take long debates to a quick call.

    The trade-off is thoroughness against flow: block only on what matters, and approve with comments for the rest.

↩ Usually asked after

More in Engineering Practice

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me