Skip to Content
Tidy First?
book

Tidy First?

by Kent Beck
October 2023
Intermediate to advanced content levelIntermediate to advanced
122 pages
1h 58m
English
O'Reilly Media, Inc.
Book available
Content preview from Tidy First?

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.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Building Micro-Frontends

Building Micro-Frontends

Luca Mezzalira
Learning Go

Learning Go

Jon Bodner
Head First Git

Head First Git

Raju Gandhi

Publisher Resources

ISBN: 9781098151232Errata Page