Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Refactors that quietly change behavior
card 4 of 6
A readable rewrite that lost short-circuiting
builds on: What the agent cannot see
The new version reads more clearly, but a list literal evaluates every element while the list is built, before `all()` sees any of them. `all()` stops at the first falsy item, but by then every call has already run. A user with no card now hits `user.card.is_valid()`, which raises `AttributeError` instead of returning `False`. Users with an invalid card now also reach `fraud.check`. **Later cost:** crashes on card-less users, plus extra fraud calls that may be billed or logged. BETTER: keep the `and` chain.
// Python
--- a/billing.py
+++ b/billing.py
def can_charge(user):
- return (user.card is not None
- and user.card.is_valid()
- and fraud.check(user))
+ checks = [
+ user.card is not None,
+ user.card.is_valid(),
+ fraud.check(user),
+ ]
+ return all(checks)
Terms on this card
- later cost
- The concrete damage a shortcut does after merge, such as a hidden bug, silent data corruption or a maintenance burden.
- list literal
- A list written out element by element, like `[a(), b()]`. Every element is evaluated, including any calls, when the list is built.
- all()
- Python built-in that returns True if every item is truthy. It stops at the first falsy item it is given, but it cannot undo calls already made to build a list.
- AttributeError
- Python exception raised when you access an attribute or method on an object that lacks it, e.g. calling a method on None.
- falsy
- A value treated as false in a condition. In JS/TS: false, 0, '', null, undefined, NaN. In Python: False, None, 0, '', empty collections.
Lesson goal: Spot 'pure cleanup' that changes behaviour: reordered side effects, a different error type, lost short-circuit evaluation, changed iteration order or null handling. Explain why callers who depend on that old behaviour break. ·
the whole lesson