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

Modules Should Be Deep

A Philosophy of Software Design · Ch 4 · Modules Should Be Deep · Ousterhout · 2nd ed 2021

中文 →

What is this chapter about?

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.

An analogy

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.

Why the old way is hard

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.

How it works, intuitively

What it buys you / how to choose

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.

Remember it in one line

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