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.
Silent fallbacks that hide bugs
card 4 of 6
Same call, opposite verdicts
builds on: Errors swallowed by catch-all handlers
// Python
`counts[w] = counts.get(w, 0) + 1` is correct. A word not seen yet really has been seen 0 times, so 0 is the true answer.
`price = prices.get(sku, 0)` is a disguise. A SKU with no price is a catalogue bug, and 0 sells the item for free. BETTER: `prices[sku]`, so a `KeyError` stops the order, or raise `ValueError(f"no price for {sku}")`.
The construct is only the tell. The verdict depends on what *missing* means in that place.
Terms on this card
- KeyError
- Python exception raised when you read a dict with `d[k]` and the key `k` is not present.
- tell
- An observable sign in a diff, transcript or summary that suggests a shortcut or an error.
- SKU
- Stock keeping unit: an ID for one product in a catalogue.
- ValueError
- Python built-in exception for a value that is the right type but unacceptable.
Lesson goal: Recognise defaults that turn a loud failure into quietly wrong data: `unwrap_or_default()`, `?? ""`, `getOrDefault`, `dict.get(k, 0)`, returning [] on a parse error. Decide when a default is genuinely correct and when the code should fail or propagate the error instead. ·
the whole lesson