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 4 of 6
Two tells in one innocent loop
builds on: What the agent cannot see
`Order.objects.all()` has no limit, so every order is loaded into memory on every request. `o.customer` is a foreign key fetched by lazy loading, which costs one extra query per order. Three fixture orders make 4 queries. 200,000 orders make 200,001. **BETTER:** `Order.objects.select_related("customer")` (one join) plus pagination. Pin the count with Django's `assertNumQueries` so it can't creep back.
// Python
--- a/shop/views.py
+++ b/shop/views.py
@@ -10,1 +10,7 @@ def order_list(request):
- return JsonResponse({"rows": []})
+ rows = []
+ for o in Order.objects.all():
+ rows.append({
+ "id": o.id,
+ "customer": o.customer.name,
+ })
+ return JsonResponse({"rows": rows})
Terms on this card
- pagination
- Returning results in fixed-size pages (LIMIT plus offset or a cursor) instead of all rows at once.
- LIMIT
- SQL clause capping how many rows a query returns.
- join
- A SQL operation that combines rows from two tables in one query, e.g. each order with its customer.
- fixture
- Prepared test data loaded before a test runs.
- foreign key
- A column pointing to a row in another table, e.g. an order's customer.
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