Book Deep-Read · A Philosophy of Software Design · Chapter 9
A Philosophy of Software Design · Ch 9 · Better Together or Better Apart? · Ousterhout · 2nd ed 2021
Programmers make one small decision all day long: should these two pieces of functionality live together, or apart? Many people have a default answer: "split everything finely; the shorter each piece, the better." This chapter says: not necessarily. Splitting has a cost of its own, and sometimes the right move is to combine.
Think of a kitchen. Keep the knife next to the cutting board and chopping is easy. Sort strictly by type instead (knives in the east cupboard, boards in the west) and it looks tidy, but every time you chop you walk to two places. On the other hand, putting dish soap and flour in the same jar is combining things that should stay apart. The test of a tidy kitchen is not how finely it is sorted, but how smoothly it works.
Someone takes a few dozen lines of code and splits them into eight pieces of two or three lines each. Every piece looks "clean." Then a reader has to jump between eight places to work out what the code actually does. Each piece is easy to read; together they are hard to follow.
When you're torn between together and apart, ask: which way leaves the reader with less to keep in mind? One honest cost: this is a judgment call that takes experience. There is no simple "split after so many lines" rule to lean on.
Whether to split depends on how easy the whole is to understand, not on how short each piece is.
Want the four costs of splitting and four signals for combining, how undo splits into a general layer and a special layer, how to split a method without making it shallow, and the public debate between the author and the author of Clean Code? → Switch to Deep
You might assume finer splits and shorter functions mean better design. Ousterhout says splitting has costs of its own, and the deciding factor is not line count but the complexity of the whole system: choose the structure with the best information hiding, the fewest dependencies, and the deepest interfaces.
Chapter 9. Chapters 4–8 covered deep modules, information hiding, general-purpose interfaces, layering, and pulling complexity down. This chapter turns those ideas into an everyday move: do two pieces of functionality go into one module or two? The next chapter turns to exception handling. In practice this chapter covers every "extract a method / split a class / merge two services" decision, and every "this function is too long" review comment.
A popular intuition says smaller modules are always better and splitting is free tidying. The author says that's wrong: splitting adds complexity, and the costs are easy to overlook. He lists four:
He also gives four signals for combining. The two pieces share information, such as a format or a piece of knowledge both rely on. They are always used together, in both directions: using A means using B, and using B means using A. They overlap conceptually, so a single higher-level concept covers both. And you can't understand one without reading the other. Ignore this and a codebase drifts into a pile of shallow modules: each one short and "clean," the combination something nobody can follow at a glance.
The author returns to the HTTP server example from Chapter 5. Students wrote "read the request from the network" and "parse the request" as two methods. But reading has to understand the request format to know when the request ends, and parsing needs the same format. The same knowledge in two places is information leakage. Merging them into one method keeps the format knowledge in one place and shortens the interface.
When two modules each do half of a job, callers often have to put the halves together by hand. Once merged, the module can do it automatically. The author's example is Java I/O. To read a file efficiently you create a FileInputStream, then wrap it in a BufferedInputStream. Almost everyone needs buffering, but everyone has to remember the extra wrapper, and forgetting it silently slows the program down. Fold buffering into the file stream and turn it on by default, and that knowledge disappears from every caller. Merging can also remove the part of an interface that only exists to pass information between two modules.
When the same code pattern keeps appearing, find a way to keep just one copy. The usual way is to extract a method. The author's caveat: it only pays off if calling the method is simpler than the code it replaces. If the original snippet is two or three lines and the new method needs a long list of parameters, nothing is saved. Another way is to restructure so the code runs in only one place. The book's example is C code that uses goto to jump to a single cleanup section at the end of a function, instead of repeating resource-release code in every error branch.
This is the chapter's one rule that clearly says split: when a general mechanism and special-purpose code share a module, pull them apart. Ideally a lower layer provides the general mechanism and a higher layer holds code written for specific cases, and the general module knows nothing about the special-purpose code. The author names this red flag Special-General Mixture.
His long example is undo in an editor. Students often put undo logic inside the text class. That mixed "keeping history," which has nothing to do with text, into the text class, and other changing state such as the selection and cursor still couldn't be undone. The author's fix is two layers. A general History module only stores a list of "actions" and supports fences that group actions together, so one undo rolls back to the previous fence. If a find-and-replace changes ten places, for example, one undo reverts all ten together. Each special-purpose module (text, selection, cursor) defines how its own actions are undone and redone. The History module never knows what an action contains, so it can serve any future feature.
The author also shows cases where separating was the wrong call. The first is the cursor and the selection. Some student projects put both in one object, reasoning that the cursor always sits at one end of the selection. The author argues this didn't simplify the interface. Instead it forced special cases like "a cursor with no selection" everywhere, and two separate objects were clearer. Sharing a little information is not enough to justify combining; what matters is whether the merged interface actually gets simpler. The second is a separate logging class: a class that only logged network errors, where each method was called from exactly one place and did one small thing. It hid nothing and just sent readers back and forth between the error site and the logger. Putting the logging back where the error happens is better.
This is the chapter's most-quoted section. The author holds that a long method is not a problem in itself. A method of a hundred-plus lines made of a few independent blocks that run in sequence is easy to read top to bottom. Splitting it just makes the reader jump around. Depth matters more than length: make methods deep first, then check whether they are short enough to read easily.
There are two ways to split a method. The good way is to extract a subtask: the child method has a clear job and makes sense on its own, so a reader knows what it does without reading its body, and the parent becomes easier to read. A common bad way is to cut a method into a first half and a second half that callers must call in order. Both new methods tend to be shallow, with interfaces almost as complex as their implementations, and callers must know the calling order. There is one test: after the split, can each method be understood without reading the others? If not, the author calls it a red flag: Conjoined Methods, two pieces that look separate but can only be understood together, meaning they should be one. In the other direction, joining methods can remove shallow interfaces, remove duplication, or pull scattered state back into one place.
The second edition adds a section answering Robert Martin's Clean Code. Martin argues that "the first rule of functions is that they should be small; the second rule is that they should be smaller than that," and the functions in his book are often just a few lines long. Ousterhout's reply: this advice puts the focus on length and encourages lots of shallow methods, each with an interface nearly as complex as its body, and readers end up jumping between them. He agrees that shorter methods are usually easier to read, but length is always a means; depth and being understandable on its own are the goal.
Table 1 · Together or apart: signals and costs
| Situation | Lean | Book's example | Cost of getting it wrong |
|---|---|---|---|
| Same knowledge in both | Combine | Reading and parsing an HTTP request | Change the format and both must change (leakage) |
| Merged interface is simpler | Combine | File stream + buffered stream | Every caller must remember the extra wrapper |
| Repeated code pattern | Combine (method or single exit) | C goto to one cleanup block | Fix one copy, miss another; but a method no simpler than the snippet is wasted |
| General mixed with special | Split | History module + per-module undo actions | General mechanism polluted, can't be reused |
| Merging forces special cases | Split | Cursor and selection | Interface no simpler, edge cases everywhere |
| Split-off class hides nothing | Merge back | Separate logging class | Readers flip between two places for zero abstraction |
Table 2 · Three options at the method level
| Option | When it's right | Cost |
|---|---|---|
| Keep one long method | Independent blocks run in sequence; reads cleanly top to bottom | Reader takes in the whole thing at once; with many blocks the key part is hard to find |
| Extract a subtask | Clear job, understandable without reading its body | One more name; a long parameter list means the cut is in the wrong place |
| Cut into two halves | Rare: each half genuinely makes sense to call on its own | Usually conjoined methods; callers track order, both sides shallow |
One test: which structure leaves the reader with the least to hold in mind at once? Line counts and class counts are only rough proxies for that.
This chapter is one of the most-used rulers in code review. "This function is 300 lines, split it" and "these little methods make me jump around, merge them" both come up. The chapter doesn't hand you a position; it gives you questions you can test against real code: can the extracted piece be understood on its own? What does it hide? The same holds at the architecture level. Split one service into two that share a data format, always deploy together, and can't function without each other, and you've just built conjoined methods with network calls and release coordination added on top.
Evidence and sources · publicly verifiable
① Whether to combine or split depends on the complexity of the whole system, not on line counts or class counts.
② Splitting has four costs: more components, glue code, related logic pulled apart, and duplication.
③ Four signals for combining: shared information, always used together, conceptual overlap, one can't be read without the other.
④ Combine when it simplifies the interface, e.g. building buffering into the file stream by default.
⑤ Removing duplication is worth it, but only if the extracted method is simpler than the snippet it replaces.
⑥ The one clear case for splitting: separate general mechanisms from special-purpose code, as with undo split into History plus each module's own actions.
⑦ Long methods are not a crime. Splitting well means extracting a self-contained subtask; splitting badly means cutting a method into halves that must be called in order.
⑧ Red flags: Conjoined Methods (can't read one without the other), Special-General Mixture, Repetition.
⑨ The 2nd edition explicitly disputes Clean Code's "smaller is better," and the authors' 2024–2025 public debate put the disagreement on the record.