Chapter 4: Reading and debugging

The bugs that take longest to find are often not in any one line. They are in what the program remembers.

State

Everything a program remembers at a given moment: its variables, what is in its database, what you have selected. The same function can behave differently depending on state, so a bug can depend on what happened before, not only on what you did just now.

Agents read code, and state is mostly not in the code. It only exists while the program runs, which is why an agent can stare at correct-looking code and find nothing. So hand it the sequence of steps, not only the symptom.

Say it to your agent

“This only fails on a second checkout in the same session. Write a test that does add, pay, new cart, add, pay in that order and checks the customer is charged twice. It should fail. Then fix it.”

The workshop

Name a word, or describe what you mean in everyday language.