Hide the detail

Think of it when you wrap something complicated behind a simpler name, or you keep reaching around a [[wrapper]] to get at what it hides.

In everyday life

A hotel minibar says “help yourself” and hides the prices. That is simple until checkout, when the guest learns each drink cost $9. A good simple view still shows the detail that changes your choice, such as the price.

One case

A clinic’s developers write remind(patient, text). It hides how the reminder travels: a push notification if the patient has the clinic’s app, a text message if not. A push costs nothing; a text message costs 4 cents. A staff member sends a flu-shot reminder to 150,000 patients through remind. 100,000 of them have no app, and the clinic pays $4,000 overnight.

Hide the detail
The ideaHow code is organized
Hide the detail

A simpler view of something that hides the detail you do not need. Good when the hidden detail rarely matters. Bad when you keep having to look past it.

How code is organized, Foundations

Every case

Every abstraction makes a bet: that its users will not need what it hides. When the bet is right, code is shorter, easier to read, and the inside can change without callers noticing. When the bet is wrong, users get surprised, as here, or they start to reach around the wrapper to the detail underneath. Cost, speed and failure are details that often matter to the person using the code, so they leak through most often.

The word

Engineers call this

abstractionA simpler view of something that hides the detail you do not need. Good when the hidden detail rarely matters. Bad when you keep having to look past it.

Hide the detail that users of your code never need. Show the detail that changes their decisions, such as cost, speed, or what happens when it fails.

Where this idea leads

Skills that encode it

  • codebase-design Matt PocockCounts error modes and performance characteristics as part of the interface, so a simple view must still tell callers about them.
  • principle-minimize-reader-load pstackCollapse wrappers that cost more than they save, and prefer boundaries that hide meaningful decisions.