liveBook · Manning

Explicit output

As explained in Grokking Simplicity

A computation result made directly available through a function's return value or another declared result channel.

An explicit output is information a function deliberately makes available through its return value. Arguments provide explicit inputs; other information entering or leaving the function remains implicit. Replacing implicit outputs with return values turns actions toward calculations. section 4.7

Use explicit outputs to make computations easier to test and reuse:

  • Return an answer instead of writing it directly to the DOM. section 4.8
  • Return a new value instead of modifying a global array. section 4.10
  • Pair returned results with explicit arguments to remove hidden dependencies. section 4.7

Returning a calculation

A tax update can keep the DOM effect at the boundary while returning the calculation from a separate function: calc_tax(amount) returns amount * 0.10, and update_tax_dom() passes that result to set_tax_dom(). section 4.10

var total = 0;
     

function add_to_total(amount) { #1
    console.log("Old total: " + total); #2 
    total += amount; #3
    return total; #4
 }

Compare the returned total with the function's other output: logging and global-state mutation remain implicit, while return total is explicit. section 4.7

How Grokking Simplicity covers it

How deep it goes
Explains return values, implicit outputs, DOM updates, globals, and copied arrays, but stops short of language internals.
Examples
Uses totals, shopping carts, DOM tax updates, and shipping eligibility to demonstrate returned results.
What it assumes
Assumes basic functions and arguments while teaching implicit inputs, implicit outputs, and side effects from zero.
What you can do after
Apply it via return values to build calculations that are more testable and reusable.
How it connects
Connects explicit outputs with functions, inputs and outputs, implicit outputs, calculations, testing, reuse, and immutability.

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.