MEPX
Chapter 3 of 10All chapters

Chapter 3 of 10

Understanding a function

Inputs, outputs, side effects.

Three questions

What comes in, what goes out, and what else does it touch? Answering those three usually explains a function without reading its middle in detail.

  • Side effects are the ones that surprise: files, network, globals, mutation of arguments.
  • A function with no side effects can be understood entirely on its own.

Names are hypotheses

Treat a name as a claim to be verified, not a fact. Names that say nothing, like handleData, usually mean several responsibilities are tangled together.