A calculation computes an output from inputs without affecting anything outside itself. The same inputs always produce the same result, regardless of when or how often it runs. section 1.20 section 3.11
Calculations form one of three fundamental code categories alongside actions and data. They represent decisions or plans, while actions carry those decisions into the outside world. section 3.1 section 3.10
Recognize a calculation by these properties:
- Takes explicit inputs and produces an output. section 1.20
- Remains unaffected by when or how many times it runs. section 1.20
- Has no implicit inputs or outputs, such as shared variables or external effects. section 4.13 section 5.3
- Can replace its call with its result without changing the program. section 3.1
Planning coupon emails
A function can decide a subscriber’s coupon rank, select coupons by rank, and generate email data. Sending the resulting emails remains an action because carrying out the plan affects the outside world. section 3.6 section 3.5
Extracting a calculation
Refactor a function that reads shared shopping-cart state into one that accepts a cart as an argument and returns a result. This makes the logic smaller, reusable, and easier to test. section 4.0 section 5.2
Visualizes the distinction between inert data and executable calculations. section 1.10
