Book Deep-Read · A Philosophy of Software Design · Chapter 14
A Philosophy of Software Design · Ch 14 · Choosing Names · Ousterhout · 2nd ed 2021
Every variable and every function in a program needs a name. This chapter is about one thing: how to choose those names. It sounds minor, yet the author gives it a whole chapter, because names are the first and most frequent thing a reader of code sees, like room numbers in a building. Mix up the numbers and people walk into the wrong room.
Years ago the author helped build an operating system. For a while, files on disk were mysteriously being overwritten by other data, and the team spent a long time hunting the cause. It turned out the code had one name, "block", that sometimes meant "which block of the file" and sometimes "which block on the disk". Two meanings shared one name, and somewhere one was used as the other. One fuzzy name, one very hard bug.
The person naming things knows exactly what they mean, so "data", "result" or "status" feels good enough. But readers aren't inside the writer's head; they can only guess from the name. Guess wrong, and they use it wrong. These small fuzzy spots don't break anything right away; they pile up until the whole program is hard to read and hard to change.
With good names, readers guess less, dig less and make fewer mistakes, and since one name gets read hundreds of times, a few extra minutes choosing it pays off. One honest cost: there's no single right length for a name; some teams prefer short ones, and the author admits that in the end the reader has to be the judge.
A name is the smallest piece of documentation: make it precise and consistent; if you can't name something well, you probably haven't thought it through.
Want to see how the file system bug happened, what "too vague" and "too specific" look like, the three consistency rules, the two red flags, and the debate between the Go community's short names and the author? → Switch to Deep
You think naming is polish you apply after the code works; Ousterhout says a name is the smallest unit of abstraction, and good names have just two properties: precision and consistency. And when you cannot find a name that is both accurate and short, the problem usually isn't your vocabulary, it's the design.
Chapter 14 sits in the middle of the book's run on comments: Chapters 12 and 13 cover why to comment and what to write, this chapter covers naming, and Chapter 15 covers writing comments first. Names and comments both use words to supply what code can't say; a name is the shortest and most frequently read piece. It is also the most direct remedy for obscurity, one of the two sources of complexity from Chapter 2. In practice it maps to the naming rules in every style guide and to the "what does this name mean?" comments in code review.
A medium-sized codebase holds tens of thousands of names, and each one is read far more often than it is written. A single bad name almost never brings a system down, so people shrug it off. But as Chapter 2 argued, complexity accumulates from hundreds or thousands of small problems, and naming is the most common of them. A vague name sends readers to the declaration, the call sites and the comments, raising cognitive load; worse, readers often don't realize they guessed wrong, and that leads straight to bugs.
The chapter offers criteria that turn "is this a good name?" from gut feel into something you can discuss, and reframes "naming is hard" as a design signal.
The author tells a real story from the Sprite operating system, which he worked on: the file system would occasionally corrupt data, with a file's block overwritten by other data. The bug was rare and hard to reproduce, and finding it took a long time. In the end, the code used many variables named block; sometimes they held a logical block number within a file, sometimes a physical block number on disk, and in one place a logical number was used as a physical one.
Because the two things shared a name, anyone reading block assumed it was the kind they expected, and the name hid the error perfectly. Had the variables been called fileBlock and diskBlock, the mistake would have been very unlikely to happen, and obvious if it did.
When choosing a name, the author says, picture what will form in the reader's mind. A name is an abstraction: a few words standing in for something far more complex, so you can think about it without the details. A good name conveys what the thing is and, just as important, what it is not.
The book gives a test you can use directly: if someone sees this name in isolation, without its declaration, documentation or any code that uses it, how closely can they guess what it refers to? If they can't, change it. The author also notes that good names are usually two or three words; squeezing into one word rarely says enough, and five or six becomes a burden.
Too vague is the common failure. Examples from the book:
getCount(): a count of what? Active connections or all connections?x and y for the cursor position: readers assume screen pixels, but they are actually character and line positions; charIndex and lineIndex remove the confusion.blinkStatus: what values does a "status" take? Does true mean on or off? Renamed cursorVisible, the meaning of true and false is self-evident. The author's advice: a boolean's name should read as a predicate.Words like data, info, result, value and status fit almost anything, so they say almost nothing. The exception is idiomatic names with tiny scopes: i and j are fine in a loop that spans only a few lines, because the reader can see every use at once.
Too specific is the other side: a method that deletes any range of text shouldn't name its parameter selection, because it can delete any range, not just what the user selected; range fits. A name that is too narrow makes readers underestimate what something can do, or read in constraints that don't exist.
That gives the chapter's first red flag: Vague Name. A name broad enough to refer to many different things tells the reader little and invites misuse.
Most programs have variables that recur again and again, such as block numbers in a file system. Consistent naming lowers cognitive load: once readers learn what a name means in one place, they can reuse that understanding everywhere. The author's three rules:
Sprite's block broke the third rule: its purpose was so broad that same-named variables did not behave alike. When code needs two variables of the same kind, distinguish them with a common name plus a prefix, such as srcFileBlock and dstFileBlock, so readers still see they are the same kind of thing. Loop variables too: always i for the outer loop and j for the inner, a habit the team can rely on.
The chapter's second red flag: Hard to Pick Name. If you can't find a name that is precise, intuitive and not too long, that is a signal that the variable or method may lack a clear definition or a single purpose. It may be doing several things, or its boundaries may be fuzzy. The fix isn't a thesaurus; it's going back to split or redefine the thing.
This ties naming to the book's main thread: something that can be described by a simple name usually has a simple abstraction; something that needs a tongue-twister of a name is usually a shallow module or a muddle of responsibilities.
Table 1 · Four naming ailments: symptom, consequence, fix
| Ailment | Looks like | Consequence | Fix |
|---|---|---|---|
| Too vague (red flag) | data, getCount, blinkStatus | Readers must dig through code to guess; easy to misuse | Say "count of what"; booleans as predicates |
| Too specific | delete(selection) | Readers underestimate it, or invent constraints | Name the real capability, e.g. range |
| Inconsistent | One name, many meanings; or one meaning, many names | Sprite-style bugs; re-learning everywhere | One purpose, one name; prefixes for siblings |
| Hard to pick (red flag) | Needs five or six words, or a tongue-twister | Exposes muddled responsibilities | Fix the design, then name it |
How long a name should be is the chapter's one genuinely contested trade-off. The author devotes a section, "A Different Opinion: Go Style Guide", to the Go community's preference for short names:
Table 2 · Short-name camp vs Ousterhout: how long should a name be
| Dimension | Go community (short names) | Ousterhout |
|---|---|---|
| Default | Keep locals short: c over lineCount | Default to precise, usually two or three words |
| Core argument | Long names obscure what the code does and tire the reader | Short names are often vague; readers have to guess |
| Common ground | The farther from its declaration a name is used, the more descriptive it must be; i in a few-line loop is fine | |
| Cost | Too little information across functions and files | Can feel verbose in tiny scopes |
| Who decides | The author's conclusion: readability must be determined by readers, not writers | |
A rule of thumb: the smaller and more local the scope, the shorter a name can be; the more public and the farther it travels, the more precise it must be. Names in a public interface are hard to change once set, so they deserve the extra time.
Naming is one of the most common kinds of code review comment, and one of the most often dropped as "just preference". This chapter's value is criteria both sides can cite: can you guess it from the name alone, does one name carry several meanings, what design problem hides behind a hard-to-pick name. Mainstream style guides broadly agree on these points, with some disagreement:
Evidence and sources · publicly verifiable (original sites unreachable from this run; text citations only)
In daily work: when review turns up handleData, tmp2 or flag, ask "could you guess what this is from the name alone?"; when one concept is uid, userId and accountId in different files, unify it under the consistency rules; when a class simply won't take a name, discuss its responsibilities before arguing over English words.
i is a good name in a short loop.① A name is the smallest abstraction and is read far more than it is written; bad names are the most common of complexity's thousand cuts.
② Sprite file system bug: block meant two things (file block number / disk block number), a mix-up corrupted data; fileBlock / diskBlock would have prevented it.
③ The test: from the name alone, with no context, can a reader guess what it refers to?
④ Precision: getCount, x/y, blinkStatus are too vague; name booleans as predicates, like cursorVisible.
⑤ Not too specific either: a parameter that can be any range is range, not selection.
⑥ Consistency: one purpose, one name; never reuse it for something else; keep the purpose narrow enough that same-named variables behave alike; prefixes for siblings.
⑦ Two red flags: Vague Name, and Hard to Pick Name; the latter usually means unclear responsibilities, so fix the design first.
⑧ The length debate: Go leans short, the author leans precise; both accept that names used farther from their declaration need more description, and readers decide what is readable.