liveBook · Manning

Mathematical calculation

As explained in Grokking Simplicity

A calculation is a category of code that deterministically computes a result from its inputs without directly interacting with the outside world.

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

Image

Visualizes the distinction between inert data and executable calculations. section 1.10

How Grokking Simplicity covers it

How deep it goes
Develops calculations from definition through JavaScript implementation, classification, testing, and extraction from actions.
Examples
Demonstrates coupon ranking, coupon selection, email planning, shopping-list generation, tax calculation, and free-shipping decisions.
What it assumes
Teaches the actions-calculations-data distinction from practical scenarios while assuming basic ability to read and write functions.
What you can do after
Apply it via explicit-input functions that isolate decisions, improve testability, and reduce actions in existing code.
How it connects
Connects calculations with actions, data, pure functions, referential transparency, side effects, testing, reuse, and distributed systems.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Simplicity. The section links point to the parts of the book it draws on.