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.
Overbuilt code: speculative abstraction and defensive clutter
card 5 of 6
Read it: three tells in 11 lines
builds on: Why agents fill gaps with plausible guesses
The only caller is `new EurFormatter().format(order.totalCents)`. First tell: `Formatter` has one implementer. Second: `cents == null` guards a `number`, which strict TypeScript already rules out. Third: the `try` wraps a division and `toFixed(2)`, and neither can throw here. **Later cost:** three layers to read for one line of logic, and a guard that suggests `null` is a legal input. **Simpler:** `const formatEur = (cents: number) =>` returning the template string.
// TypeScript
interface Formatter {
format(cents: number): string;
}
class EurFormatter implements Formatter {
format(cents: number): string {
if (cents == null) return "";
try {
return `€${(cents / 100).toFixed(2)}`;
} catch { return ""; }
}
}
Terms on this card
- strict TypeScript
- Compiling with the `strict` option, including strictNullChecks, so `null` and `undefined` are only allowed where a type explicitly includes them.
- toFixed
- JavaScript number method that formats a number with a fixed count of decimals; it throws only if the count is outside 0–100.
- template string
- A JavaScript/TypeScript string in backticks that can embed expressions with ${...}.
- tell
- An observable sign in a diff, transcript or summary that suggests a shortcut or an error.
- later cost
- The concrete damage a shortcut does after merge, such as a hidden bug, corrupted data or extra maintenance.
Lesson goal: Spot code bigger than the task needs: interfaces, factories or config options with one user, generic frameworks for a single case, and redundant null checks and try/catch on paths that cannot fail. Explain the later cost: more code to maintain, contracts blurred by defensive checks, and real bugs hidden in noise. Name the simpler version. ·
the whole lesson