Book Deep-Read · A Philosophy of Software Design · Chapter 15
A Philosophy of Software Design · Ch 15 · Write The Comments First · Ousterhout · 2nd ed 2021
When programmers write code, they often leave short notes beside it telling the next person "what this part does and how to use it." Those notes are called comments. Most people's habit is to finish the program, get it working, and add the comments at the end — if they remember. This chapter makes one suggestion that runs against that habit: flip the order. Write the explanation first, then the code.
Imagine you're inventing a new board game. One way is to build the board and print all the cards, then play and see. Another is to take a sheet of paper and write the rules in a few sentences. If five sentences cover it, the game is probably good. If two pages still don't make it clear, you know the rules are a mess before you've spent a cent on cards. The author says writing a program's explanation is writing that rule sheet.
"I'll add it at the end" sounds efficient, but it's the easiest step to skip: once the program runs, people rush to the next task. Even when the notes do get written, the reasons behind the design are half forgotten by then, so the notes just read the code back aloud, which helps no one. Worse, the explanation could have exposed a design flaw — but written last, the flaw is already built into the walls.
The moment the code is done, the explanation is done too — and it's better, because it was written while your thinking was clearest. The author even says this turns comment-writing into one of the most enjoyable parts of design. One honest cost: when you change your mind mid-design, the early notes have to change with it, which takes some discipline.
Explain first, code second: if the explanation flows, the design is probably right; if it doesn't, fix the design first.
Want the author's exact order, the "Hard to Describe" red flag, how much time comments really cost, and his public debate with the author of Clean Code about comments and test-first development? → Switch to Deep
You think comments are "documentation work" done after the code; Ousterhout says comments belong inside the design process. Write the interface comments before the code and they stop being an after-the-fact chore and become a design tool: if something's comment won't come out simple, the thing itself is usually badly designed.
Chapter 15, closing the comments sequence: Chapter 12 covers why to write comments, Chapter 13 what to write, Chapter 14 naming, and this one when to write them. It turns "comments are the abstraction" into a working process, and loops back to Chapter 4's deep modules and Chapter 11's "design it twice." In practice it maps to design-doc-first and contract-first habits.
Chapter 12 knocked down the excuses for not commenting, but a practical problem remains: even when everyone agrees to write them, comments still often come out poor. The author observes that many developers put documentation off until the end, after coding and unit testing are done. He considers this one of the surest ways to get low-quality documentation:
The chapter asks: where in the development process should comments be written so that they are good and also improve the design?
The book describes how the author writes a new class:
The direct result: when the code is done, the comments are done too, with no backlog. Note it is not "write a complete document, then start coding" — comments and code advance together; it's just that for every new interface the words come before the implementation.
Writing first, the author's head is full of abstractions and design intent, not implementation details, so interface comments naturally describe "what this is and how to use it" rather than restating code. That is exactly the kind Chapter 13 asks for: a level above the code, supplying intuition the code can't express. Write them last and you are steeped in details; climbing back to that level is hard.
The author calls this the biggest payoff of commenting first. As Chapter 12 argued, comments are the only way to fully capture an abstraction: a signature is just a skeleton; parameter meanings, side effects and preconditions live in the comment. So writing an interface comment means writing down the abstraction and seeing whether it holds up.
Hence the chapter's red flag, Hard to Describe: the comment for a method or variable should be simple and yet complete; if you struggle to write such a comment, the thing you're describing may have a design problem. Typical signs:
The author likens comments to the canary in the coal mine of complexity: miners carried canaries because the birds succumbed to gas first. When a comment won't flow, the design is raising an early alarm, and fixing it now costs a few lines of prose and a signature. This also makes Chapter 11's "design it twice" practical: write the interface comment for each candidate; the one that comes out shorter and smoother is usually the deeper one.
The author admits he enjoys this stage: commenting first means thinking about the overall shape of the system, the most creative part of design, whereas retrofitting comments is a chore done under duress. Once comments stop being a debt and become the design itself, the attitude changes too.
The usual worry is "no time." The author offers a rough estimate: typing code and comments is only a small fraction of total development time, most of which goes to thinking, debugging and understanding; even if comments are half of what you type, writing them probably accounts for around 10% of total development time. In return you get better designs and less misuse and debugging, so he believes the investment likely saves time overall.
The other worry is "the design will change and I'll have to rewrite them." His answer: comments written first evolve with the design, updated as you change it; it's retrofitting at the end that creates a pile of work requiring you to reconstruct everything from memory.
Table 1 · When to write comments: three approaches
| Approach | Comment quality | Effect on design | Cost |
|---|---|---|---|
| Retrofit at the end | Often missing; when present, mostly restates code | None — problems are already in the code | Backlog piles up; high recall cost |
| Comment while coding | Middling; tends to hug the implementation | Limited, mostly at the implementation level | Comments describe "how" rather than "what" |
| Interface comments first (this chapter) | High; written while intent is clearest | Canary: awkward to write → change the design | Must be updated as the design shifts; needs discipline |
The chapter also invites a comparison with test-first development (TDD, test-driven development: write a failing unit test, then the code). Both put "something before the implementation," but different things:
Table 2 · Comments first vs tests first
| Dimension | Comments first (Ousterhout) | Tests first (TDD) |
|---|---|---|
| What comes first | The abstraction: what this class / method is and how to use it | A test case for one specific behavior |
| Unit of work | A class, or a group of related methods | One test, often a few lines of code |
| Strength | Forces you to think through the whole interface; exposes shallow modules | Behavior has executable checks; safe regressions |
| Weakness | Prose isn't executable and can drift from code | The author thinks it slides into tactical programming, squeezing design out |
| Combine? | Yes: settle the abstraction with interface comments, then write unit tests for that group of methods. What the author opposes is advancing one test at a time, not tests themselves | |
Rule of thumb: the more public the interface and the harder the boundary is to change later, the more it pays to comment first; a small helper used once inside one function can have a very short interface comment, but the order still holds.
The idea recurs at every scale: "interface comment first" for a method, "design doc first" for a project, "press release first" for a product. The common thread is testing an idea with prose that must be clear before investing in an implementation.
Industry evidence · publicly verifiable
10–100× that of incorrect ones. Martin holds that every comment is a failure to express intent in code — "a necessary evil." On testing, Ousterhout proposes writing code in units of a few methods or a class and then its tests (both agreed to call this "bundling"), precisely so that development centers on design rather than tests. Source: GitHub · johnousterhout/aposd-vs-clean-codeDay to day: when reviewing a new class, read only its interface comments first — can you tell in a minute what it offers? Before building, share the key methods' comments and signatures as a draft; reviewing that is far cheaper than reviewing hundreds of lines of implementation. When handing a task to an AI coding assistant, writing the function's interface comment first and letting it fill in the body follows the same logic.
① Comments left to the end almost guarantee poor documentation: often skipped, and when written, they restate the code.
② The author's order: class interface comment → key methods' comments and signatures (empty bodies) → instance variable comments → bodies; new methods get their comment first too.
③ Result: when the code is done, the comments are done; no backlog.
④ Benefit one: written while design intent is clearest, comments describe abstractions, not implementation.
⑤ Benefit two (the biggest): comments are a design tool, the canary of complexity; red flag "Hard to Describe" — if a comment can't be simple and complete, the design has a problem.
⑥ Benefit three: early comments are part of design, and fun to write.
⑦ Cost: writing comments is roughly 10% of total development time (the author's rough estimate), in exchange for better designs.
⑧ Versus TDD: what comes first is an abstraction, not a single test; the two can be combined.