Read Code Fast
Lesson 22 Scope creep
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.
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}"
- Line 2 A deleted guard. It handled orders with no
lines. Nobody asked to remove it, and without it those orders raise KeyError. - Line 3 The list comprehension was rewritten as a loop and the helper
moneywas swapped out. Churn that is not part of the task. - Line 7 This
ifand the line below it are the only lines the task needed. - 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.