liveBook · Manning

Implicit input

As explained in Grokking Simplicity

An input obtained by a computation from surrounding state or context rather than supplied explicitly as a function argument.

An implicit input is information a function receives without an argument. Reading a global variable is a common example: surrounding state enters the computation invisibly. section 4.7 section 4.10

Keep these distinctions in view:

  • Explicit inputs arrive through arguments; implicit inputs arrive through any other route. section 4.7
  • Actions may have implicit inputs and outputs, while calculations have none by definition. section 4.13
  • Implicit inputs couple a function to surrounding state, limiting when it can run and making testing harder. section 5.3

Turning a global read into an argument

A shipping rule that reads shopping_cart_total can run only when that global is correctly set. Change gets_free_shipping(item_price) to gets_free_shipping(total, item_price), then pass shopping_cart_total at the call site. The rule remains an action if it performs other effects, but its calculation depends on an explicit input. section 4.10 section 5.4

function update_shipping_icons() {
    var buy_buttons = get_buy_buttons_dom();
    for(var i = 0; i < buy_buttons.length; i++) {
        var button = buy_buttons[i];
        var item = button.item;
        if(gets_free_shipping(shopping_cart_total, item.price))    
            button.show_free_shipping_icon();
        else
            button.hide_free_shipping_icon();
    }
}
 
function gets_free_shipping(total, item_price) {
    return item_price + total >= 20;
}

Compare the shipping rule before and after replacing its global cart-total read with an explicit total argument. section 4.10 section 5.4

Reduce implicit inputs incrementally rather than trying to eliminate every action. Identify each hidden read, replace it with an argument, and update callers. The result is more modular, reusable, and testable. section 5.3 section 19.9

How Grokking Simplicity covers it

How deep it goes
Explains hidden reads, global-state coupling, and argument conversion through worked shopping-cart refactorings; it stops short of eliminating all actions.
Examples
Demonstrates shopping carts, shipping icons, tax calculations, DOM updates, and asynchronous cart totals.
What it assumes
Assumes basic functions and global variables while teaching inputs, outputs, actions, and calculations from their operational behavior.
What you can do after
Diagnose/debug with it by locating hidden global reads and converting them into arguments to improve reuse and testability.
How it connects
Connects implicit inputs with actions, calculations, explicit inputs, global variables, return values, immutability, testing, and reusability.

Also explained in

Compare how 2 books explain implicit input →

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.