liveBook · Manning

Explicit input

As explained in Grokking Simplicity

An input to a function that is supplied directly at the call site through an argument or parameter.

An explicit input is information supplied directly to a function through an argument. In JavaScript, arguments are the explicit inputs, while other ways information enters—such as reading a global variable—are implicit inputs. Making inputs explicit reveals what a function needs and improves reuse and testability. section 4.7 section 4.10

Passing the cart explicitly

A function that reads shopping_cart hides one of its inputs. Change update_shipping_icons() to update_shipping_icons(cart), then pass shopping_cart at the call site. The function still performs UI actions, but its cart dependency is now visible. section 5.4

Use explicit inputs when extracting calculations or generalizing duplicated functions:

  • Identify information entering through a global variable or another hidden dependency. section 4.7
  • Add an argument, replace the hidden or hard-coded value in the function body, and update every caller. section 10.4 section 14.11
  • Generalize repeated operations by exposing values such as field names, nested keys, or modifier functions as arguments. section 10.4 section 14.10
  • For calculations, pair explicit inputs with return values instead of hidden mutation or other implicit outputs. section 4.10 section 4.7

From specialized functions to a reusable one

Replace setPriceByName(cart, name, price), setQuantityByName(), and similar functions with setFieldByName(cart, name, field, value). The field name becomes a first-class value that callers can pass and store. section 10.4

How Grokking Simplicity covers it

How deep it goes
Defines explicit inputs, demonstrates dependency conversion, and gives a four-step refactoring procedure; it stops short of language internals.
Examples
Uses shopping-cart functions, field-update functions, nested options, and JavaScript array copying to expose hidden inputs.
What it assumes
Assumes basic functions and callers, while teaching the distinction between explicit arguments and implicit information from zero.
What you can do after
Apply it via JavaScript refactoring by identifying hidden dependencies, adding arguments, changing function bodies, and updating callers.
How it connects
Connects explicit inputs with implicit inputs, arguments, return values, calculations, side effects, and first-class values.

Also explained in

Compare how 2 books explain explicit 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.