Chapter 4: Reading and debugging

Pure function

A function whose answer depends only on its inputs, and which changes nothing else. Same input, same output, every time. Code that is not pure is called impure, which is no insult: impure code does the useful work.

Pure functions are the easiest code to review, because you can understand one without knowing about the rest of the program. Asking an agent to push its logic into them is one of the cheapest ways of getting code you can check.

Say it to your agent

“Split out calculateDiscount(cart, coupon) as a pure function: no database, no clock, no global state. Pass today's date in as a parameter. Test it with a table of inputs and expected outputs.”

The workshop

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