Book Deep-Read · Software Engineering at Google · Chapter 8
Software Engineering at Google · Ch 8 · Style Guides and Rules · Shaindel Schwartz · 2020
Google has tens of thousands of engineers, nearly all writing code in one giant shared repository. Everyone has habits: how far to indent, how to name things, which fancy tricks to reach for. This chapter is about how Google sets the "house rules" for writing code — and who those rules actually serve.
Think of a city's traffic code. "Drive on the right" is not smarter than "drive on the left" — the British manage fine. What matters is that everyone in the city does the same thing, so nobody crashes. Other rules really do prevent danger, like a lower speed limit outside schools. And some are just advice, like "turn on your headlights in the rain": no fine, but experienced drivers do it anyway.
Many of Google's rules forbid a "cleverer" way of writing something, for one reason only: the reader won't follow it. The writer wants a neat shortcut; the rule says no — because code is written once but read by dozens of people for years.
Should your team have coding rules? Look at how many people there are and how long the code must live. A handful of people on a small project can get by with a verbal agreement; dozens of people maintaining code for years should write the rules down and let tools enforce as much as possible. The honest cost: rules always flatten some personal preferences and locally better choices, and too many of them turns into bureaucracy.
Rules aren't about looking pretty — they make code written by thousands of people read as if one person wrote it.
Want the five principles for making rules, the three kinds of rules, where rules end and guidance begins, how gofmt ended formatting wars, and the real reason Google's C++ avoids exceptions? → Switch to the deep read
You think a style guide is about whether code "looks nice"; this chapter says it is about readability and maintainability at scale: the only legitimate reason for a rule is to keep the codebase manageable over time and headcount — so every rule must pull its weight, optimize for the reader rather than the writer, and be handed to a tool whenever a tool can enforce it.
gofmt or C++'s clang-format.The first chapter of Part III, "Processes." It takes Ch1's thesis — software engineering = programming × time × scale — down to the most everyday level, how each line gets written, and leads into Ch9 Code Review (human enforcement of the rules) and Ch20 Static Analysis (automated enforcement).
Google's single repository holds roughly 2 billion lines worked on by tens of thousands of engineers (the order of magnitude disclosed in CACM, 2016). Engineers switch teams often, and code written by one person today may be inherited tomorrow by someone on another continent. Without shared rules, every team and every person has a dialect: reading someone else's code starts with "translating" its style; reviews burn time on indentation and braces; automated refactoring tools can't cope with endless variations; and dangerous language features creep in here and there, laying traps only experts can spot.
The chapter answers three questions: why rules exist, which rules to make, and how to get tens of thousands of people to actually follow them. Its stance is clear: rules are not a display of taste but a tool with a cost — every rule must be remembered, followed and sometimes compromised on by every engineer — so it has to be paid for.
The chapter first separates two words. Rules are hard requirements — "must / must not" — enforced by reviewers and tools. Guidance is recommendations and best practices — "prefer / should" — that help you write better but aren't mandatory. Google's style guides keep only the most necessary rules; guidance lives in teaching material of many shapes: language courses, C++ "Tips of the Week" (some later published through Abseil), and advice in reviews.
Why separate them? Because writing advice down as rules bloats the rulebook until nobody can remember it, while writing truly important constraints down only as advice fails to stop accidents. The split is itself a trade-off.
The chapter (and the "Goals" section at the top of Google's public C++ style guide) lists the tests a rule must pass:
goto — not because goto is fine, but because it is already vanishingly rare, so a rule would only add memory burden.By purpose, the rules in a style guide fall into roughly three groups:
The three groups differ in how strictly and how automatically they can be enforced: consistency rules can almost all go to a formatter; danger rules can mostly be caught by static checks; best-practice rules depend most on human judgment and are carried mainly by review and readability.
Rules are not frozen. The chapter stresses that each decision in the style guide comes with its rationale, precisely so that later you can judge whether it should still exist — when the original reason no longer holds, the rule should change. Each language has a small group of senior engineers acting as style arbiters, who evaluate proposed changes and make the final call; decisions rest on trade-off analysis, not anyone's personal preference. Rules also allow exceptions, but the bar is high: only when following the rule clearly costs more.
The best public example is the C++ guide's stance on exceptions. It says its "advice against using exceptions is not predicated on philosophical or moral grounds, but practical ones": Google's existing code is not exception-tolerant, so adding exceptions costs more — and it admits that "things would probably be different if we had to do it all over again from scratch." That is the template for "concede to practicalities" plus "record the rationale": a rule that admits it is a trade-off made under historical conditions.
Writing a rule down is only the start; tens of thousands of people follow it because of an enforcement chain. The chapter describes three layers:
The gofmt case study is the chapter's highlight. Go has shipped with the official formatter gofmt from the start, with almost no tunable layout options — it produces one format. As a result, the Go community has almost no formatting debates; more importantly, once formatting is uniform, machine rewriting of code becomes safe — an automated tool edits the code, runs gofmt, and the output is indistinguishable from hand-written code, paving the way for large-scale automated changes (Ch22).
Table 1 · Rules vs. guidance: which side does it belong on
| Dimension | Rules | Guidance |
|---|---|---|
| Tone | Must / must not | Prefer / should |
| Enforcement | Review rejects, tools block | Teaching, review suggestions; doesn't block merge |
| Good for | Dangerous features, consistency conventions | Techniques, design taste, idioms |
| Cost | Each extra rule is one more thing everyone remembers; too many = bureaucracy | Not mandatory, so it can't stop real accidents |
Table 2 · Enforcement mechanisms: who guards a rule
| Mechanism | Fits rules about | Scalability | Honest cost |
|---|---|---|---|
| Formatter | Indentation, line breaks, spacing, import order | Nearly unlimited; one investment, whole codebase benefits | Accept a format that's "nobody's favorite"; the first codebase-wide reformat creates a huge diff |
| Checker / presubmit | Dangerous features, mechanically decidable best practices | High | Too many false positives and engineers ignore or bypass it; rules must be precise |
| Code review | Meaningful names, right abstractions | Grows linearly with reviewers | Slow, subjective, argument-prone; wasted most on formatting |
| Education / readability | Reasons behind rules, language idioms | Slow, but shapes long-term habits | Heavy up-front cost; certification can bottleneck merges |
The rule of thumb: if a machine can decide a rule, don't make people guard it; if it needs human judgment, don't make it a hard rule. A small team (under ten people, code living a year or two) often needs just a formatter plus a one-page convention; at hundreds of people and a ten-year lifespan, a written guide, arbiters and a certification process start paying off.
This chapter hands you a yardstick for reviews and interviews alike: for any "should we add this rule" debate, ask whom it optimizes for, what it costs, and whether it can be automated. Asked in an interview "how do you keep a team's code style consistent," the strong answer isn't "we hold a meeting" but "formatting goes to a formatter, dangerous patterns to a linter, and review looks at design." It also explains why low- or zero-config formatters like Prettier, Black and rustfmt spread through their ecosystems — the same line of thinking as gofmt.
Industry evidence · publicly verifiable
goto to show that an already "vanishingly rare" problem doesn't merit a rule. Google C++ Style Guide · Goals / Exceptions ↗dataclasses and enum) — the "avoid surprising constructs" principle made concrete. Google Python Style Guide · Power Features ↗① The only reason rules exist: keep the codebase manageable over time and scale — not to display taste.
② Separate rules (must / must not, enforced) from guidance (advice, taught); don't let advice bloat into rules.
③ Five principles: pull their weight, optimize for the reader, be consistent, avoid error-prone constructs, concede to practicalities.
④ Three kinds of rules: avoid danger, enforce best practice, build consistency; for consistency, having an answer beats which answer.
⑤ Every rule records its rationale and is changed by style arbiters on trade-offs; when the reason is gone, the rule should go.
⑥ C++ without exceptions is the template for practicality: the reason is existing code, not philosophy — from scratch it might differ.
⑦ Enforcement chain: formatter → checker / presubmit → human review; what a machine can decide, people shouldn't guard.
⑧ gofmt: one format ends the debate and makes machine rewriting safe, paving the way for large-scale changes.
⑨ Pitfalls: style ≠ formatting; more rules isn't better; tools need low false positives; Google's rules carry Google's history.