liveBook · Manning

Chapter 5: Improving the design of actions

What you will learn in chapter 5 of Grokking Simplicity

The chapter introduces why improving actions means reducing, rather than eliminating, their implicit inputs and outputs.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces why improving actions means reducing, rather than eliminating, their implicit inputs and outputs.

Key terms: actions, calculations, implicit inputs and outputs

5.1 Aligning design with business requirements

The section shows why mechanically extracting a calculation may leave a function poorly aligned with the business question, and identifies duplicated logic as a design warning.

Key terms: level of abstraction, get_free_shipping(), current cart, new item, duplication, code smell, calc_total()

5.2 Aligning the function with business requirements

The section changes the free-shipping function to answer a question about a shopping cart, then discusses the design tradeoffs of small calculations and copying the cart.

Key terms: gets_free_shipping(), cart, signature, modified copy, add_item(), cart array, lines of code, small functions, calculations, cohesive

5.3 Principle: Minimize implicit inputs and outputs

Defines implicit inputs and outputs and explains why reducing them makes functions, including actions, easier to reuse and test.

Key terms: implicit inputs, implicit outputs, arguments, return value, calculations, actions, modular, testability, reusability

5.4 Reducing implicit inputs and outputs

This section applies the principle of minimizing implicit inputs by replacing global-variable reads with function arguments and updating callers.

Key terms: implicit input, explicit input, argument, global variable reads, action

5.5 Giving the code a once-over

The section gives the shopping-cart actions a final cleanup by removing an unused global variable and inlining an unnecessary function.

Key terms: shopping_cart_total, calc_cart_total(), add_item_to_cart(), inline

5.6 Categorizing our calculations

The section groups shopping-cart calculations by what they know or do, showing how those groups can become layers of meaning in the code.

Key terms: cart operation, item operation, business rule, layers of meaning

5.7 Principle: Design is about pulling things apart

The section presents pulling functions apart as a design principle and explains why smaller functions are worth trying.

Key terms: separate concerns, argument, composed back together, reuse, maintain, test, extract

5.8 Improving the design by pulling add_item() apart

The section separates item creation from cart updating in add_item() while keeping the copy-and-modify steps together as copy-on-write.

Key terms: add_item(), structure of items, structure of carts, copy-on-write, immutability

5.9 Extracting a copy-on-write pattern

This section turns a shopping-cart-specific array operation into a reusable copy-on-write utility.

Key terms: copy-on-write discipline, add_item(), utility function

5.10 Using add_item()

Shows how callers change after add_item() is refactored to accept an item instead of separate name and price arguments.

Key terms: add_item(), cart, item

5.11 Categorizing our calculations

The section categorizes calculations by what they know and uses the shipping-icon function to practice separating different responsibilities.

Key terms: cart operation, item operation, business rule, array utility, code smell, update_shipping_icons(), buy button operations, cart and item operations, DOM operation

5.12 Smaller functions and more calculations

The section applies action, calculation, and data labels to the new code and reiterates that one action makes an entire function an action.

Key terms: action, calculation, data, A, C, or D

5.13 Conclusion

The conclusion highlights how the design changes have organized the shopping-cart code, while deferring further bugs and immutability to later sections.

Key terms: actions, structure of our data, interface functions

5.14 Summary

5.15 Up next…

This section previews the next two chapters on immutability and a later return to design.

Where this is used later

Concepts explained in this chapter

← Chapter 4: Extracting calculations from actions Chapter 6: Staying immutable in a mutable language →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.