All courses

A clean, focused change

Recognise a mergeable change: one purpose per commit, no debug prints, commented-out code, dead helpers or stray files, it follows the codebase's conventions, and the commit message explains why the change was made.

Builds on: Scope creep and unasked-for changes in a diff, What 'done' means for a change

Read it card by card Start the whole course

It works. Is it mergeable?

You asked the agent to make invoice totals round half-up to the cent. It reports done, tests green. The diff holds the fix: an import and two lines. It also holds a `print`, a commented-out old line, a helper nothing calls and a new file `scratch_test_round.py`. The commit message reads "Update invoice.py". The code works. Would you merge it as is?

Why the agent leaves its scaffolding behind

The agent works by trial. It prints values to see them, tries one approach, keeps the old one just in case and writes a scratch script to check. Once tests turn green it stops, and nothing pushes it to tidy code that still passes. It writes the message from the diff, so it says *what* changed. The *why* is in your ticket or your head. **Later cost**: noisy logs, misleading code, a broken helper someone reuses, and history nobody can explain.

Checklist for a clean, focused change

1. **One purpose**: state it in one sentence without "and". If you can't, split the commits. 2. **No leftovers**: debug output (`print`, `console.log`, `dbg!`, `fmt.Println`, `System.out.println`), commented-out code, unused functions or imports, and files nothing uses (`*.orig`, logs, notes, scratch scripts). 3. **Conventions**: naming, logging, error style, and file and test placement match the neighbouring code. 4. **Message**: the subject says what changed, the body says why.

Three lines of fix, the rest is leftovers

The fix is the import change plus the `q` and `quantize` lines. Everything else is a tell. The `print` runs on every invoice in production and fills the logs. The commented-out line leaves readers wondering whether to restore it. `_round_v1` is called nowhere. It also rounds half to even and returns a float, the very behaviour being fixed, so whoever reuses it brings the bug back. The scratch file ships in the repo, and the next reader has to work out whether it matters. All of it goes before merge, not in a later cleanup.
// Python
--- a/billing/invoice.py
+++ b/billing/invoice.py
@@ -1 +1 @@
-from decimal import Decimal
+from decimal import Decimal, ROUND_HALF_UP
@@ -12 +12,7 @@
-    return round(total, 2)
+    print("DBG total", total)
+    # return round(total, 2)
+    q = Decimal("0.01")
+    return total.quantize(q, ROUND_HALF_UP)
+
+def _round_v1(x):
+    return float(f"{x:.2f}")
--- /dev/null
+++ b/scratch_test_round.py

A commit message that says why

BAD: `Update invoice.py`, or `Use Decimal.quantize`. The diff already shows that. BETTER: `Round invoice totals half-up to the cent` `round()` rounds exact halves to even, so a total of 0.125 became 0.12 and invoices were a cent off the tax PDF. Use `Decimal.quantize` with `ROUND_HALF_UP`. Fixes BILL-412. The agent can only write this if you give it the reason in the task.

Remember

A mergeable change does one thing and contains only the lines that do it. It looks like the code around it, and its message says why. Debug output, commented-out code, unused helpers and stray files left over from the agent's trial and error are tells. Have them removed before merge.

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.