Book Deep-Read · A Philosophy of Software Design · Chapter 4
A Philosophy of Software Design · Ch 4 · Modules Should Be Deep · Ousterhout · 2nd ed 2021
The first three chapters said software's biggest enemy is complexity. This one hands you the book's first and most important weapon: build the system out of "deep" parts — parts that are dead simple to use but do a huge amount of work behind the scenes. When you tap "Save" on your phone, hundreds of thousands of lines of code go find space on the disk, queue the writes and guard against power loss, and you never need to know a single one of them. That is depth.
Driving a car takes one steering wheel and two pedals. However complicated the engine, gearbox and brake lines are, the driver never has to care — a tiny control surface, a lot of work underneath. That is a good part. Now picture a car where the accelerator is split into a fuel lever and a spark lever, and changing gear means pulling three separate rods. Each rod is simple on its own, but you have to learn all of them and pull them in the right order, and if you forget one, the car stalls.
Many programmers are taught that "smaller is better": keep each piece of code short, make each module do one tiny thing. It sounds tidy. The result is a system chopped into lots of little parts, each with its own instruction manual. No single part is hard; the hard part is that the user now has to read dozens of manuals and know how to fit the parts together. The complexity didn't go away. It just moved out of the parts and onto the people using them.
It gives you a ruler you can use anywhere: judge a module not by how short or small it is, but by how much hassle it hides from the people who use it. Whether to split or merge, measure with that ruler. One honest cost: a deep part is thicker and harder to build on the inside. The person who writes it works harder so that everyone who uses it works less.
A good part is like a steering wheel: simple to use, a lot of work behind it. A part whose manual is as long as its work hasn't helped anyone.
Want the cost/benefit math of interface vs. implementation, the two opposite ways an abstraction goes wrong, why Unix file I/O is the gold standard of depth, why reading a file in Java takes three classes, "classitis," and Ousterhout's public debate with the author of Clean Code? → Switch to Deep
You think the mark of a good module is being small; Ousterhout says it is being deep: the simplest possible interface over the most powerful possible functionality. The interface is the cost users pay; the functionality is the benefit the module delivers. A shallow module, whose interface is about as complex as its implementation, barely lightens anyone's load — and a system carved into many shallow modules is one of the main sources of complexity.
Chapter 4 is where the book turns from mindset (Chapter 3, strategic programming) to concrete craft, and it is the axis of the whole book: information hiding (Ch 5), general-purpose modules (Ch 6), pulling complexity downward (Ch 8) and "together or apart" (Ch 9) are all answers to how do you make modules deeper? In practice it maps onto every code review that asks "should this class be split further?"
Chapter 2 traced complexity to dependencies and obscurity. Dependencies can't be eliminated — modules have to cooperate — so the real question is: how do you divide a system so that a developer only has to face a small piece of it at any moment? Modular design is the textbook answer, but divide it wrong and things get worse: more modules mean more interfaces, and more for users to learn.
The book's anchoring scene: to read serialized objects from a file in Java, you create a FileInputStream, wrap it in a BufferedInputStream, then wrap that in an ObjectInputStream — three classes, three constructors, for one task. Forget the middle layer and the program still runs; it just has no buffering and is much slower, with no error to warn you. Every class is "small and single-purpose," yet together they push the whole burden onto the caller. The chapter's job is to give a criterion that tells this kind of split apart from a good one.
Ideal modularity would make modules completely independent, so a developer could change one without understanding any other. Reality can't get there, but the goal is to minimize dependencies. So each module has two parts: the interface describes what it does, the implementation handles how. A developer working inside a module needs its interface and implementation, plus the interfaces of the modules it uses — but not their implementations.
That yields a way of looking at things: the interface is the cost a module imposes on the rest of the system (every user has to learn it), and its functionality is the benefit. A good module is one whose benefit far exceeds its cost. It's also why a "good interface" isn't measured by "few methods" per se, but by how little the user has to know.
An interface has two layers. The formal part is spelled out in code: method names, parameter types, return values, exceptions — the compiler can check it. The informal part is what a signature can't express: the high-level behavior (say, "deletes the file named by its argument"), ordering constraints ("must call A before B"), side effects. The informal part is usually much larger and more complex than the formal part, can only be captured in comments, and no compiler checks it for you.
When you size up an interface's cost, count the informal part: a method with just two parameters that requires "initialize first, never call concurrently, clean up by hand afterwards" actually has a heavy interface.
An abstraction is a simplified view of an entity that omits unimportant details; a module's interface is its abstraction to the outside. It can go wrong in two directions:
The book's example is the file system. It completely hides which disk blocks hold your data, and rightly so. But for an application like a database, when data actually reaches durable storage is an important detail, so the file system has to offer a way to force it (such as fsync). The key to designing an abstraction is separating what matters from what doesn't — and keeping the "what matters" list short.
The author draws each module as a rectangle: its area is the functionality, the width of its top edge is the interface. The best modules are narrow and tall — small interface, lots of functionality. The worst are wide and flat — an interface nearly as big as the functionality.
The gold standard: Unix file I/O. The basic interface is just five system calls — open, read, write, lseek (move the read/write position) and close — all with simple signatures. Yet, the author notes, modern implementations take hundreds of thousands of lines of code, hiding how files are laid out on disk, how directories form a hierarchy, how permissions are checked, how concurrent access is scheduled, how reads and writes are cached, and how different storage devices are driven. The implementation has been rewritten countless times over the decades; those five calls have barely changed. Another dividend of depth: the implementation can change radically and users never notice.
Another example: garbage collection. The garbage collector in languages like Go and Java has almost no interface at all — you call nothing, and memory gets reclaimed. It hides an enormous amount of machinery and actually shrinks the system's overall interface (no more freeing memory by hand). That is depth taken to its limit.
A shallow module is one whose interface is complicated relative to the functionality it provides. The book's extreme example:
private void addNullValueForAttribute(String attribute) { data.put(attribute, null); }
From the standpoint of managing complexity, this method makes things worse: it offers no abstraction — all its functionality is visible in its interface. Understanding its name and parameter is no easier than just reading data.put(attribute, null), and it adds one more name to learn and one more line of code. The author flags this as a red flag: an interface that is complicated relative to the functionality it provides. The book concedes shallow modules are sometimes unavoidable (a linked-list class, for instance) and not useless, but they don't help much in the battle against complexity.
Why are shallow modules so common? The author names a popular belief he calls classitis: "classes are good, so more classes are better," along with "classes should be small" and "split any method longer than N lines." Following that advice, developers chop functionality as fine as possible, ending up with many shallow classes — each simple on its own, the system as a whole more complex: the total interface surface explodes, and using any one feature means understanding how several classes fit together.
The lesson behind the Java example is an interface design principle: interfaces should make the most common usage as simple as possible. Almost everyone reading a file wants buffering, so it should be the default; for the rare caller who doesn't, provide a way to turn it off. Unix does exactly this: most programs read and write sequentially, so sequential access is the default, and the few that need random access make one extra lseek call. If an interface has many features but most users only need to know a few of them, its effective complexity is just the complexity of the commonly used ones.
Table 1 · Three shapes a module can take
| Shape | What it looks like | Examples | Cost |
|---|---|---|---|
| Deep module | Small interface, lots of functionality, common case needs zero setup | Unix file I/O, garbage collectors | Thick, hard-to-write implementation; designers work harder; internal changes must keep the interface stable |
| Shallow module | Interface about as complex as the implementation | addNullValueForAttribute, linked-list class | One more name to learn, saves almost nothing; occasionally unavoidable |
| Classitis (many shallow classes) | Each class tiny and single-purpose; the caller composes them | Java's three-layer InputStream | Total interface surface explodes; the common case means assembling several objects, and missing a step raises no error |
Table 2 · "Should I split out another class / method?"
| Usual reason | Ousterhout's view | The question to ask |
|---|---|---|
| "This method is over N lines" | Length itself isn't the problem; splitting off shallow methods adds interface | Is the split-off piece's interface much simpler than its implementation? |
| "A class should do one small thing" | "Small" isn't the goal; "deep" is | How many classes must a user understand at once to use this feature? |
| "Give callers maximum flexibility" | Flexibility that complicates the common case is a burden | Can nine in ten callers get it right with zero configuration? |
| "Expose every detail for transparency" | May mean leaking unimportant details | Does the user really need to know this? |
The rule of thumb: adding a module should shrink the total interface users must know (because it hides something), not grow it. If users have to know more after a split, it went the wrong way.
In interviews and design reviews, "deep module" gives you a question that lands harder than "high cohesion, low coupling": what does this interface hide from its callers? A good storage engine, a good SDK, a good internal service all turn the common path into one or two calls and hide retries, caching and sharding inside. Conversely, if callers must invoke five methods in a specific order and assemble their own configuration to get it right, that module is shallow no matter how "single-responsibility" it is.
Evidence and sources · publicly verifiable
java.nio.file.Files class added in Java 7 (2011) offers static methods that read a whole file in one call (such as readAllLines) and a newBufferedReader that returns a buffered reader directly — exactly the direction this chapter argues for: make the common case simple and buffering the default. Source: Java SE 7 API documentation, java.nio.file.Files① Module = interface + implementation; the interface is the cost users pay, functionality is the benefit delivered.
② The mark of a good module isn't "small," it's "deep": simple interface, powerful functionality.
③ Interfaces include an informal part the signature can't express — behavior, call order, side effects — captured only in comments.
④ Abstractions fail two ways: including unimportant details (bloat) or omitting important ones (false abstraction).
⑤ Gold standards: five Unix file calls over hundreds of thousands of lines; garbage collection with almost no interface.
⑥ Shallow-module red flag: an interface complex relative to its functionality, like addNullValueForAttribute.
⑦ "Classitis": the belief that more, smaller classes are better yields swarms of shallow classes and a more complex system.
⑧ Make the common case simplest: buffering should be the default — Java's three-layer streams are the counterexample, Unix the model.
⑨ Test: a new module should reduce what users must know; judge splits by depth, not line count.