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.
Fine on test data, broken at scale
card 5 of 6
A validator that hangs on one input
builds on: What the agent cannot see
The agent adds `/^(\w+\s?)*$/` to check display names in TypeScript. Tests with `"Ada Lovelace"` pass instantly. **Tell:** a repeated group that can split the same text many ways, because `\s?` may match nothing. Thirty letters plus `!` give the backtracking engine about 2²⁹ splits to try. That blocks Node's event loop, the single thread that serves every request. **BETTER:** `/^(?:\w+\s)*\w*$/` accepts the same strings but matches each in only one way. Go's `regexp` and Rust's `regex` run in linear time; JS, Python and Java engines do not.
Terms on this card
- regex
- Regular expression: a pattern language for matching text.
- JS
- Short for JavaScript. Plain JS has no compiler check of names or arguments.
Lesson goal: Recognise code that passes small tests but fails on production volumes: N+1 queries from ORM calls inside loops, unbounded queries with no pagination, reading whole files or tables into memory, quadratic list lookups in loops, and regexes prone to catastrophic backtracking. Explain why the agent cannot see this coming, and which check (query log, profile, large fixture) exposes it. ·
the whole lesson