Chapter 10. Explicit Parameters
You’re reading some code you want to change, and you notice that some of the data it works on wasn’t passed explicitly to the routine. How do you make the inputs clear?
Split the routine. The top part gathers the parameters and passes them explicitly to the second part.
It’s common to see blocks of parameters passed in a map. This makes it hard to read and understand what data is required. It also opens up the horrific abuse of modifying the parameters for (implicit) use later.
For example, if you see this:
params = { a: 1, b: 2 }
foo(params)
function foo(params)
...params.a... ...params.b...
Make the parameters explicit by splitting foo:
function foo(params)
foo_body(params.a, params.b)
function foo_body(a, b)
...a... ...b...
Another case for explicit parameters is when you find the use of environment variables deep in the bowels of the code. Make the parameters explicit, then be prepared to push them up the chain of calling functions. This will make your code easier to read, test, and analyze.