Read Code Fast

Lesson 22 Scope creep

6 min read · Python · Quiz

unasked rewrites, deleted code, duplicate helpers, needless abstraction

What you'll learn

  • Separate the change you asked for from the extras
  • Question deleted guards, renames and duplicate helpers
  • Ask for the smallest change that does the job

You asked for one small change. The AI sends back a diff that touches the whole file. Every extra line is something you now have to review.

The idea

AI loves to "improve" while it is in a file: it renames things, deletes guards that look unnecessary, adds a second helper that does what the first one did, or wraps a one-line job in a class. Each change might be fine, but none were asked for, and each can break something that was working.

Read a diff with one question: does this line serve the request? Lines that do are the change. Lines that don't are scope creep: ask the AI to take them out, or review them as carefully as new code. A deleted line deserves the most suspicion: someone put it there for a reason.

invoice.py (task: show the coupon)
1 def invoice_lines(order):2-    lines = order.get("lines") or []3-    return [f"{l['name']} {money(l['cents'])}" for l in lines]4+    lines = []5+    for l in order["lines"]:6+        lines.append(f"{l['name']} {format_price(l['cents'])}")7+    if order.get("coupon"):8+        lines.append(f"Coupon {order['coupon']}")9+    return lines10+11+def format_price(cents):12+    return f"${cents:.2f}"
  1. Line 2 A deleted guard. It handled orders with no lines. Nobody asked to remove it, and without it those orders raise KeyError.
  2. Line 3 The list comprehension was rewritten as a loop and the helper money was swapped out. Churn that is not part of the task.
  3. Line 7 This if and the line below it are the only lines the task needed.
  4. Line 11 A second helper that duplicates money, and it prints different text for the same input.

Take away

  • Read a diff with one question: does this line serve the request?
  • Deleted guards and renamed functions are the riskiest extra changes.
  • A duplicate helper is a bug waiting: two versions will drift apart.

Quiz: test yourself

7 questions: a quick quiz, then a review drill. Pick an answer to see why it's right.