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.
Duplicating code instead of reusing it
card 5 of 6
When merging is the wrong fix
builds on: What the agent cannot see
Not every lookalike is a duplicate. Take two `format_price` functions. Invoices need exactly two decimals plus the currency code. The shop page uses the locale's symbol, sometimes with no decimals. Merge them into `format_price(x, for_invoice=True)` and you get the wrong abstraction: one function serving two rules that change for different reasons. Every page tweak now puts invoices at risk, and the flags keep piling up.
Ask: *if one changes, must the other change too?* Yes: keep one shared copy. No: keep both and name each by its purpose.
Terms on this card
- locale
- A user's language and region settings, which decide formats such as currency symbols and decimal separators.
- wrong abstraction
- One shared function forced to serve rules that change for different reasons, usually held together by flags.
Lesson goal: Spot a new helper, validator or client that duplicates one already in the codebase that the agent never opened. Explain the later cost when the copies diverge, and when merging the copies would instead create the wrong abstraction. ·
the whole lesson