Chapter 4: Reading and debugging

Side effect

Anything a function does beyond handing back its answer: writing to a database, sending an email, changing something outside itself, even printing. A program's useful work is mostly side effects, and so is most of its risk.

An agent retrying a failed step reruns its side effects, so the email goes out twice and the card is charged twice. When you read its code, find the lines that change the outside world. Those are the ones you can't take back.

Say it to your agent

“Keep the calculation and the charge apart. Put the total in a plain function with no I/O and test that, and make chargeCard the only place that talks to Stripe, using an idempotency key.”

The workshop

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