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.
Happy-path code: the edge cases it skipped
card 5 of 6
Walking the probes through it
builds on: Why agents fill gaps with plausible guesses
**Empty:** `avg_stars([])` computes 0 / 0 and raises `ZeroDivisionError`, so a new product's page errors. **Absent:** a review with no `"stars"` key raises `KeyError`. **Boundary:** `page(r, 1)` starts at index 20, so the first 20 reviews never show. Nothing errors, because Python slices clamp, and even a page past the end just returns `[]`. One test shows it: `assert page(list(range(25)), 1) == list(range(20))` is red. What empty should return is your call, so tell the agent.
Terms on this card
- ZeroDivisionError
- Python's exception raised when dividing by zero, for example by `len()` of an empty list.
- KeyError
- Python's exception raised when you read a dict with `d[key]` and the key is not present.
- slices clamp
- In Python, a slice range past the end of the list is silently cut to the list's length instead of raising an error.
- red
- A test or check that is failing.
- tell
- An observable sign in a diff, transcript or summary that suggests a shortcut or an error.
Lesson goal: Probe agent code for the structural inputs it typically ignores: empty collections, None/null/nil and missing keys, zero and negative values, and off-by-one boundaries on ranges, slices and pagination. Predict which of these a given function will mishandle, and write the one test that would show it. ·
the whole lesson