Skip to content

Write Reasonable Code

Write code that is easy to reason about. This makes it easier to spot errors and reduces overhead from needing to jump across multiple files and functions etc.

Reasoning is easier when it can remain local:

  • Small scopes with minimal dependencies
  • Clear and explicit data inputs and outputs
  • Explicit data use and ownership

Relevant techniques:

Reasonable code is what you get when you needn’t look across multiple files, you needn’t look across a large section, or ponder with difficulty over many logical decisions within the code itself.

- Jimmy Hoffa on https://the-whiteboard.github.io

Local reasoning is the ability to look at a defined unit of code, a function, or a class, understand it, and verify its correctness without understanding all the contexts within which it is used.

- Sean Parent on https://sean-parent.stlab.cc

Write code that reads like the problem that it solves