Book Deep-Read · A Philosophy of Software Design · Chapter 17
A Philosophy of Software Design · Ch 17 · Consistency · Ousterhout · 2nd ed 2021
You can find the checkout and the exit in almost any supermarket within seconds, because supermarkets are laid out in much the same way. Software works the same. In a program with hundreds of thousands of lines, if the same kind of thing is always done the same way, a newcomer who learns it once can read it in a hundred places. This chapter is about that: consistency, and why "I have a better idea" is usually not a good enough reason to break it.
Think of a city's traffic lights: red means stop and green means go, everywhere, so drivers never have to think about it. Now one engineer decides blue is more visible and makes blue mean stop at their intersection. Blue may really be more visible, but every driver in town will make mistakes at that corner. A good idea that differs from everything around it becomes a trap.
Software is written by many people over many years. Everyone has habits, and each habit makes sense on its own. The result is three or four ways of doing the same thing. Readers must work out each spot from scratch. Worse, they guess based on what they learned elsewhere, guess wrong, and a bug slips in.
Code becomes faster to read, mistakes become rarer, and people spend their energy on real problems instead of arguing about style. One honest cost: sticking to the rules sometimes means living with an old approach that is not the best.
Do similar things the same way; "I have a better idea" is not enough unless it is good enough to change every old place too.
Want the five places consistency shows up, the four ways to keep it, when consistency goes too far, and how Google, Python and Go wrote it into their own guides? → Switch to Deep
You might think consistency is just a tidiness preference; Ousterhout treats it as a powerful tool for reducing complexity: when similar things are done in similar ways and dissimilar things in different ways, readers get leverage — learn once, apply everywhere. The price is discipline: having a "better idea" is not a sufficient excuse to introduce inconsistencies.
Chapter 17, in the book's later group on making code obvious. It builds on Chapter 14, "Choosing Names" (consistent names are a special case), and Chapter 16, "Modifying Existing Code" (keep existing conventions when you change things), and leads into Chapter 18, "Code Should be Obvious" — consistency is one of the main sources of obviousness.
Chapter 2 named three symptoms of complexity: change amplification, cognitive load and unknown unknowns. Inconsistency worsens the last two at once. Picture a service maintained by a 20-person team with three ways of handling errors: some functions return error codes, some throw exceptions, some return null. For every function a reader must first figure out which camp it belongs to. Worse, they guess based on the camp they know best, miss a call that never throws but quietly returns null, and the error is swallowed.
Such inconsistency rarely comes from laziness. It usually comes from good intentions: everyone believes their own way is better. The chapter answers three questions: what consistency buys; how to keep it in a codebase touched by many people over many years; and when and how it may be broken.
The central claim: consistency creates cognitive leverage. Once you have learned how something is done in one place, you can immediately understand every other place that does it the same way. Without consistency, each place has to be learned separately.
It also reduces mistakes. In a consistent system, developers can safely assume that something that looks like X really is X, and the assumption holds. In an inconsistent one, the same assumption walks people into traps. That is why the author files consistency among the tools that make code obvious: readers can guess correctly without studying the details.
Consistency is hard to maintain, especially on projects with many people over many years: one group doesn't know another's conventions, newcomers don't know the rules, and they introduce new, conflicting conventions. The author's remedies:
The sharpest rule in the chapter: don't change existing conventions. You may think the old approach is flawed and have a better one in mind. But, the author argues, the value of consistency over inconsistency is almost always greater than the value of one approach over another. Use the new approach only in your new code, and the system now has two ways; every reader must remember both.
When is a change allowed? The bar is high: first ask whether the new approach is good enough to be worth the time to update all the old uses. If it is, update all of them. If you won't or can't update them all, don't introduce it. Afterwards, update the documentation and the checking tools as well, so the new convention is the only one.
The flip side matters just as much: dissimilar things should not be forced to look alike. Reusing a variable name for things that behave differently, or squeezing a problem into a design pattern that doesn't fit, creates false consistency — readers believe the things are the same when they are not, which is worse than obvious inconsistency. Consistency is only valuable because developers can trust that if something looks like X, it really is X.
The author closes by placing consistency within the investment mindset of strategic programming: keeping things consistent takes extra effort — learning the conventions, writing checkers, nit-picking in review, migrating old code — but it pays back on every later read and change, which become faster and less error-prone.
Table 1 · When you want to use a "better" approach
| Situation | What to do | Cost |
|---|---|---|
| No clear technical winner | Pick one and have everyone follow it | Someone gives up a preference; you save the recurring arguments |
| New way slightly better | Follow the existing convention | Live with a suboptimal approach for now |
| Clearly better, full migration feasible | Change every old use at once; update docs and checkers | Large migration; a big diff needs tests behind it |
| Better, but can't migrate it all | The chapter's position: don't introduce it | May forgo an improvement; a common industry compromise is gradual migration with old usages clearly marked |
| The two things really differ | Make them look different too (different names, different structure) | One more concept to learn, but no misleading the reader |
Table 2 · Four ways to ensure consistency
| Means | Good at catching | Misses | Cost |
|---|---|---|---|
| Document | Newcomers who don't know the conventions | People who know but forget or don't look | Low, though the document needs upkeep too |
| Enforce with tools | Conventions that can be checked mechanically: format, naming, banned constructs | Judgment calls such as interface style or choice of pattern | Write the rule once; nearly free afterwards |
| When in Rome | Local conventions (a module's own habits) | Surrounding code that is already a mess | A few extra minutes of reading before writing |
| Code review | Judgment-based conventions, while teaching newcomers | Conventions the reviewer doesn't know either | Review time; excessive nit-picking wears people down |
Rule of thumb: hand every convention a tool can check to a tool, and spend review attention on the parts that need judgment. Local consistency matters more than global — two styles within one file or one set of related interfaces do the most direct damage.
Almost every large engineering organization's style guide puts consistency above any specific rule, and formatters plus static checks have turned "enforce it with a tool" into everyday infrastructure.
Industry evidence · publicly verifiable
gofmt emits one standard style; if its answer doesn't seem right, rearrange the program or file a bug about gofmt, don't work around it. That is this chapter's "enforce" taken to its limit. Source: Effective Go · FormattingIn practice: spend half an hour learning an unfamiliar codebase's conventions before changing it; encode team conventions in formatters and lint rules wired into pre-commit and CI; in review, separate what tools can police from what needs a human; and when an AI assistant edits code, ask it to imitate the surrounding code rather than apply its own preferences.
① Consistency is a powerful tool against complexity: do similar things similarly and dissimilar things differently.
② It creates cognitive leverage — learn once, understand everywhere — and makes "looks like X, is X" a safe assumption, so fewer mistakes.
③ It shows up in five places: names, coding style, interfaces, design patterns, invariants.
④ Keep it by documenting, enforcing with tools (no commit unless it passes), following local custom, and nit-picky code review.
⑤ "I have a better idea" is not enough to introduce inconsistency: consistency is almost always worth more than one approach's edge over another.
⑥ To change a convention, it must be worth updating every old use — and you must actually update them all.
⑦ Don't overdo it: making different things look the same is false consistency that misleads readers.
⑧ Local consistency matters most; give every mechanically checkable convention to a tool.
⑨ Real-world echoes: Google's style guide, PEP 8, Go's gofmt; like strategic programming, consistency is an investment.