5 Improving the design of actions

In this chapter
- Discover how eliminating implicit inputs and outputs can enhance reusability.
- Learn to improve the design of our code by pulling things apart.
In the last chapter, we learned how eliminating all implicit inputs and outputs can convert an action into a calculation. However, you can’t eliminate all of them. You need some actions. In this chapter, we see how even eliminating some of the inputs and outputs can improve the design of actions.
Aligning design with business requirements
Choosing a better level of abstraction that matches usage
The refactoring from actions to calculations that we did was fairly mechanical. It doesn’t always lead to the best possible design. That takes a more human touch. Let’s look at that now. In fact, Kim has an idea for how to improve it.
The function gets_free_shipping()
is not quite right. The idea was to know if an order with the current cart and a new item would result in free shipping. But this doesn’t ask about the order, it asks about a total plus an item’s price. It takes the wrong arguments.

function gets_free_shipping(total, item_price) { #1 return item_price + total >= 20; #2 }
We also have a subtle duplication. We’re adding an item price to a total in two places. Duplication isn’t always bad, but it is a code smell. Code smell means an indicator of a potential problem.