Book Deep-Read · A Philosophy of Software Design · Chapter 5

Information Hiding and Leakage

A Philosophy of Software Design · Ch 5 · Information Hiding (and Leakage) · Ousterhout · 2nd ed 2021

中文 →

What is this chapter about?

The previous chapter said good parts should be "deep": easy to use, doing lots of work behind the scenes. This chapter answers the obvious next question: how do you build a deep part? The answer is one of the oldest and best ideas in software: lock each "how it's done" secret in one place, and don't let it scatter. When you fill in a web form and hit "Submit," the program on the server gets your name with a single line of code. How it dug that name out of a long stream of bytes is something the app developer never has to know.

A strange thing first

A program has three jobs: read a file, change a few things, write it back. The obvious split follows the steps: a "reader" part, a "changer" part, a "writer" part. Looks tidy. Then one day the file format changes, and you discover the reader and the writer both have to change; miss one and things break. Splitting by steps quietly split one secret into two copies.

Why the old way is hard

When people write programs, the first thing that comes to mind is "what happens first, what happens next." So many systems get cut along the lines of a flowchart. The trouble is that several steps often need the same piece of knowledge: the same file format, the same shape of a network message. Once that knowledge is copied into several parts, it's like a recipe handed to three cooks: change the recipe and you must tell all three, and nobody warns you if you forget one.

How it works, intuitively

What it buys you / how to choose

It gives you a new question for carving up a system: not "how many steps is this," but "which decision here might change later, and who alone should guard it?" Split that way, each change lands in one place, and newcomers only need to learn the front door. One honest cost: hide too much and it backfires; if something the outside really needs is locked away, users are left stuck.

Remember it in one line

One secret lives in one part. Split by who needs to know what, not by what happens first.

Want to see what information hiding actually hides, why a private field is not information hiding, how to fix "back-door leakage," how temporal decomposition wrecks a student HTTP server step by step, why getParameter is a good interface, and where hiding goes too far? → Switch to Deep