# Lessons for AI coders: when working code is expensive
Date: 20 November 2026
The short version
An AI assistant wrote a working feature in one pass. Then a human asked four questions, and the same feature became half the size.
The first version worked. The second version is cheaper to own. The difference is not skill. The difference is who pays for maintenance.
This article compares both versions of one small feature: an Enrol button on a card. The refactored design is described in Clean state in a card UI.
The feature
A card lists people. Each person has a button that enrols or unenrols them in a round. A second button enrols everyone on the page.
Small feature. Obvious behaviour. Good test case.
Version 1: the AI answer
The first version did this:
- The button stored state in
data-enrol, in its label text, in a CSS class, and indisabled. Four copies of one fact. - The script set the label, swapped the class, added and removed a warning icon, and changed the tooltip after every click.
- The endpoint returned a count:
{ "enrolled": 3 }. The script assumed every requested pair had succeeded. - A single click refetched every card on the page to show the result.
- Two endpoints existed: one for a single change, one for a batch.
- Tests checked the label text and a CSS class name.
Every line worked. The feature shipped. Nothing in the code was wrong in isolation.
Version 2: after four questions
The human asked:
- Where does this fact live?
- Who draws the settled state?
- What does the response promise for each item?
- Will this survive a redesign?
The answers changed the shape:
- One fact lives on the element,
data-enrol. A transientdata-statedrives CSS. The script never touches a colour or a class. - The participant row moved into
_ParticipantCell.cshtml. The card renders it, and the action returns it. One template draws the row both times. - One endpoint takes parallel arrays:
personIds,roundIds,enrols. A click sends one pair. The bulk button sends every pair. One transaction, one response. - The response is HTML, one cell per pair, with an explicit
data-removedmarker. - The script swaps cells, then refreshes only the cards that changed.
- Tests check behaviour and stored rows, not styling.
The comparison
| Item | Version 1 | Version 2 |
|---|---|---|
| Copies of the enrolment fact | 4 | 2 |
| Code paths for enrolment | 2 endpoints + 2 script blocks | 1 endpoint + 1 function |
| Requests after one click | 1 POST + every card | 1 POST + 1 card |
| Places that know the warning rule | 2 | 1 |
| Script lines in the card block | 244 | 186 |
| Tests coupled to CSS | yes | no |
| Effort to change the button style | edit script and CSS | edit CSS |
| Effort to add a badge | edit partial only | edit partial only |
The line count is the smallest part of the gain. The gain is that a future change has one obvious place to go.
Why AI produces version 1
This is not a criticism of any one model. It is a description of the incentives.
- **It optimises for the current request.** A prompt asks for a working button. Working is a testable state. Maintainable is not.
- **It reasons locally.** The script can see the row, so it patches the row. It does not feel the cost of the same fact living in four places, because the cost arrives in six months.
- **It has no memory of the last change.** A human who edited that file three times has a physical dislike of the fourth edit. An AI starts fresh and will happily add a fifth copy.
- **It follows patterns in its training data.** A large share of published code toggles classes and text by hand. That pattern is common, so it is reproduced.
- **It cannot feel the review.** Nobody sighs when reading duplicated logic, because the author is not present.
A fair description: a capable junior with no memory of last week and no ownership of next quarter. The output is often correct and rarely minimal.
The debt is real, and it compounds
Each duplicated fact is a place to forget:
- A new state arrives and three places need it.
- A redesign renames a class and one test fails for the wrong reason.
- A batch save half fails and the summary count reports success anyway.
- A removal case returns an empty string, and the next reader cannot tell empty from broken.
None of these are crashes. They are slow taxes, paid by the next person.
What a human adds
The human contribution in this case was not typing speed. It was four questions, asked in the right order:
- **Ownership.** Which layer owns this fact? Answer: the server owns enrolment. The button owns only the in-flight state.
- **Single renderer.** Which code draws the row? Answer: the partial. Both paths call it.
- **Contract.** What does one response promise for one item? Answer: the rendered result, or an explicit removal marker. Not a count.
- **Cost of the next change.** Where will the next edit land? Answer: one template, one action, one CSS block.
True programmers ask these questions because they have paid for the answers before.
A review checklist for AI output
Use this on any AI-written change before merge:
- Does one fact live in one place?
- Does any script set a class, a colour, or a label from a flag? If yes, can CSS or the server do it instead?
- Does the browser rebuild markup that the server already knows how to draw?
- Does a response carry a summary where a per-item result is needed?
- Does a user action cause more than one request per affected card?
- Are there two code paths that differ only by count?
- Do tests assert behaviour, or do they assert styling?
- Can a new reader find the rule in one file?
- Would a redesign break a test that proves nothing about behaviour?
- If this fails halfway, does the UI tell the truth?
Ten questions. Two minutes. Usually one refactor.
The best combination
For the foreseeable future, the strongest setup is both, each on its own work.
AI does what a person cannot match for speed:
- Typing volume, at a pace no hand keeps.
- Boilerplate: models, view models, wiring, test scaffolding.
- Syntax recall for a language or library the person has not used.
- Fast exploration: three variants while a person types one.
A person does what a model cannot feel:
- Architecture: which layer owns each fact.
- Curiosity: what happens when this fails halfway?
- Taste: the physical dislike of the fifth copy of one fact.
- Longing for simple: cut the feature until it fits in one place.
| Work | Better owner |
|---|---|
| Typing volume and boilerplate | AI |
| Syntax and library recall | AI |
| First draft of a test suite | AI |
| Which layer owns a fact | Person |
| What a response promises per item | Person |
| What to delete | Person |
| Names for the next reader | Person |
Alone, each side is weaker. A fast author with no memory of next quarter. A careful reviewer who has lived through the fourth edit and is slow to type.
Together, one side produces volume and the other keeps the shape. That combination is available today, and it is a wonderful one. Use it on purpose: let the AI write, and keep the architectural questions for the person.
A note on tone
AI output is improving quickly, and a working first draft is genuinely valuable. The point of this article is not that AI writes bad code. The point is that AI writes code that works now, and a person must decide whether it is worth owning later.
The best results here came from a loop, not from either party alone. The AI produced a working version fast. The human rejected two of its decisions and asked for a simpler shape. The AI then produced the simpler shape, also fast.
That loop works when the human asks about maintenance and the AI takes the constraint seriously.
Summary
- Working code is the start of the job, not the end.
- A duplicated fact is a future bug with a delay.
- Let the element hold state and let CSS draw it.
- Let the server render settled state and let the browser swap it.
- One endpoint can serve one item and many items.
- Test behaviour, not styling.
- Ask where the next change will land before you accept the first draft.
The full refactored design, with code: Clean state in a card UI.