liveBook · Manning

Action spreading rule

As explained in Grokking Simplicity

A rule stating that action status propagates upward through caller paths in a function call graph.

The action spreading rule says that when a function calls an action, it becomes an action too; every caller above it on that path is also an action. This distinguishes reusable calculations from operations with side effects. section 18.18

Use the rule to expose design and testing consequences:

  • Calling logAddToCart() inside the calculation add_item() turns add_item() and all its callers into actions. section 9.11
  • A caller such as update_shipping_icons() may invoke add_item() merely to calculate a possible cart, causing false logging when no item was added. section 9.11
  • Keep the action above the abstraction barrier when the caller captures user intent and already dispatches the required work. section 9.11

Logging a cart addition

Place logAddToCart() in add_item_to_cart(), the add-to-cart click handler, rather than inside add_item(). The handler already performs actions such as updating the DOM and can log the confirmed user intent without contaminating reusable cart calculations. section 9.11

Image

A call-graph diagram makes the upward propagation of action status visible: one action marks every box on the path to the top as an action. section 18.18

How Grokking Simplicity covers it

How deep it goes
Defines propagation through a call graph and works through a shopping-cart logging example, stopping short of formal graph analysis.
Examples
Uses add_item(), update_shipping_icons(), add_item_to_cart(), and logAddToCart() in a shopping-cart call path.
What it assumes
Assumes familiarity with functions and callers while distinguishing actions from calculations through concrete examples.
What you can do after
Diagnose unintended side effects and relocate actions to callers that capture user intent.
How it connects
Connects actions with calculations, abstraction barriers, stratified design, function call graphs, reuse, and testing.

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.