THE READING ROOM / BOOK GUIDE
The elements of programming style
A short, example-driven guide to writing clearer code, built on the conviction that programs are read by people and that style can be taught through revision.
About the book
The Elements of Programming Style grew out of a column Kernighan and Plauger wrote for computer magazines in the early 1970s. They collected flawed snippets submitted by readers, rewrote them, and drew general rules from each repair. The method is inductive: show a bad program, explain what makes it hard to follow or maintain, then show a better version. Programming is treated as a writing discipline, where clarity, structure and restraint matter more than cleverness.
The book addresses the practical craft of composing code: naming, control flow, data organization, comments, error handling and the testing of assumptions. Its examples come from the Fortran, PL/I and BASIC era, though the principles travel. Kernighan and Plauger argue that many bugs begin as stylistic confusion, and that a programmer who rewrites for readability often exposes defects. The advice is aphoristic and memorable, but each maxim is anchored in a concrete before-and-after example rather than asserted as taste.
How to read it
Read it as a set of worked exercises rather than a reference manual. Pause at each flawed example and try to spot the problem before reading the authors' diagnosis. The value lies in training your eye, so the book rewards slow, active reading over a quick skim. The prose is compact and occasionally dated in idiom, but the reasoning is usually plain.
The examples use older languages and small programs, which can make some idioms feel remote. Translate the principle rather than the syntax: a rule about loop structure or variable naming still applies in a modern language even when the sample code does not compile today. Readers who want a systematic treatment of software design should look elsewhere; this book is about local decisions and habits of expression.
Who it suits
Programmers who have learned syntax but want to write code others can maintain will find the most here. It suits students, self-taught developers and reviewers who need vocabulary for explaining why a piece of code is hard to read. Teachers can use the examples as discussion material. Anyone seeking a rigorous treatment of algorithms or architecture will get little from it, because the scope stays close to the sentence-level craft of programs.
Reading considerations
The examples date from the 1970s and reflect the languages and conventions of that period, so some advice reads as period-specific. Later editions and reprints vary in pagination and framing, so check which printing you have if you plan to cite passages. The rules are heuristics, not proofs; a few will strike modern readers as overly strict, and testing them against your own codebase is part of the exercise.
Follow the HN conversation
30 different recommenders are recorded in the upstream dataset. These are AI-classified source counts, not an independent rating.
Search HN comments about this book ↗
Explore videos on the same subject ↗
Book notes prepared with DeepSeek, using catalogue records and Open Library subject information. They are reading guidance, not a personal review or a verified chapter-by-chapter account. Book details can vary by edition. HN data methodology · Book metadata and covers.
