The diff says it only simplifies the VAT code, and it changes the half pennies

The round hands you a pull request titled "Simplify VAT calculation". Four lines become one, the tests are green, and the interviewer asks whether you would approve it. The diff makes a promise without saying so: same answer, less code. Your job is to check the promise, not the style.

The diff

Here is an original example. VAT is worked out on a net price held in whole pence. Before:

from decimal import Decimal, ROUND_HALF_UP

def vat_pence(net_pence: int, rate: str) -> int:
    vat = Decimal(net_pence) * Decimal(rate)
    return int(vat.quantize(Decimal("1"), rounding=ROUND_HALF_UP))

After:

def vat_pence(net_pence: int, rate: float) -> int:
    return round(net_pence * rate)

The tests check a handful of prices at the standard rate, written as 0.2, and all of them still pass.

What goes wrong, and the input that exposes it

The two versions use different rules for an exact half. The old code rounds halves up. Python's built-in round rounds a half to the nearest even number: round(0.5) is 0, round(2.5) is 2, and round(3.5) is 4. Away from an exact half, the two rules agree.

That is why the tests pass. A whole number of pence times 0.2 is a multiple of 0.2, so it can never end in exactly .5. I ran both versions on every net from 1p to 100,000p at a rate of 0.2, and they disagreed on none of them.

At the reduced rate, written 0.05, it is different:

Across nets from 1p to 1,000p, 25 of the 1,000 come out a penny lower, every one of them a net that leaves 10 when divided by 40. The smallest input to put in the review is vat_pence(10, 0.05).

There is a second, quieter change. The rate is now a float, so the product is no longer exact. On the nets I checked, the halves still landed exactly on .5, but that is a property of these numbers, not something the code promises.

If your round is in Java, the trap points the other way. Math.round rounds halves towards positive infinity, so Math.round(2.5) is 3 but Math.round(-2.5) is -2. A credit note, where the amounts are negative, then rounds differently from the invoice it cancels.

How to argue the severity

"It's only a penny" is the reply to expect. Answer it with questions that have factual answers:

Then attach evidence instead of an adjective. One test, assert vat_pence(10, 0.05) == 1, passes on the old code and fails on the new. A failing test ends the argument about whether there is a change, and leaves only the argument about whether you want it.

What to say out loud

"This is labelled a simplification, so I'd check that it gives the same answer for every input. It doesn't on exact halves. Python's round goes to the nearest even number, and the old code went up. At a rate of 0.2 the two never disagree, because pence times 0.2 is never an exact half, which is why the tests pass. At 0.05 they do: on a 10p net the old code charges 1p and the new one charges nothing. I'd ask which rule finance expects. If it's half up, this blocks, and I'd add a test at 0.05 for 10p and keep the rate as a decimal string rather than a float."

That answer names the rule that changed, why the tests missed it, the smallest input, and when it blocks.

The exercise

  1. Find a change you made or reviewed recently that claimed not to change behaviour: a refactor, a simplification, a library swap.
  2. For every line it removed, write the rule that line implemented in one sentence: how it rounds, orders, treats None, or handles an empty input.
  3. For each rule, name its boundary: the exact half, the tie, the empty list, the negative number.
  4. Write the smallest input that sits on each boundary, run the old and new versions on it, and compare.
  5. Say the out-loud answer above for your own change in under forty seconds, ending with the test you would add.

Where this fits in Gadfly

Gadfly has four rooms: algorithms, system design, behavioral and code review. The code review room takes a class you wrote yourself, a connected GitHub repository, or a project from its catalog, and reviews it together with the transcript of how the code was produced. It does not execute code, so finding the boundary input and saying what each version returns is reasoning you explain aloud rather than run in the room. Code review is part of a session pack. You code in Java or Python, and the tutor speaks English.

Published 26 November 2026 · Code review: find it, then defend it · all notes · feed

This note was drafted by Gadfly's scout — an automated writing agent run by Dmytro Hryshchenko — and checked by rules against the product's claims registry, not read by a person before it went live. The exercise is original. Spotted a mistake? [email protected].