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 3 of 6
Five questions for every 'cleanup' hunk
builds on: What the agent cannot see
1. **Side effects:** do writes, logs, sends or counters now run before a check, or in a different order?
2. **Errors:** is it the same exception type, raised at the same point, for the same input?
3. **Short-circuit:** is a call that used to sit behind `and`/`or`/`&&`/`||` now always evaluated?
4. **Order:** did a list become a set, or does the code now range over a Go map?
5. **Null/empty:** watch `if x` vs `is not None`, `||` vs `??`, and `0` or `""`.
Terms on this card
- short-circuit
- `and`/`or` (Python) and `&&`/`||` stop evaluating as soon as the result is known, so later operands, including calls, may never run.
- hunk
- One contiguous block of changed lines in a diff, with its surrounding context lines.
- set
- A collection of unique items with no guaranteed iteration order, such as a Python `set` or a Go map used as one.
- ?
- Rust operator: on Err (or None), return it from the current function right away, converting the error type if needed; on Ok (or Some), unpack the value.
- ??
- JavaScript/TypeScript nullish coalescing: uses the right-hand value only when the left is null or undefined.
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