
The elements of programming style
by Brian W. Kernighan, P. J. Plauger · first published 1974
96mentions
30recommended by
69HN commenters
2008–2026first – last mentioned
43% recommend54% neutral3% critical
Why HN recommends it
Short, quick read that teaches clear, simple coding by rewriting real poor code from other textbooks, mostly Fortran and PL/I. Much of the advice still holds; suits programmers wanting style fundamentals.
Common criticism: Examples and some advice feel dated, e.g. GOTO and Fortran-era idioms
Summarised by Claude from recommending comments
Affiliate links. As an Amazon Associate I earn from qualifying purchases.








…called "spaghetti code." I had no idea (before the classes) who was giving me good advice and who was giving me bad advice. My code was unorganized and a total mess. In my class, our textbook was "The Elements Of Programming Style" by Kernighan and Plaugher. As far as I'm concerned, it is THE book for beginning programmers. It's rare and expensive now, but worth it. In a nutshell, it taught: - program in a direct way, do NOT…
on “Advice to new programmers” ↗…bought it. It's really good because you can read it in a few hours and learn a lot. I follow many of the rules and guidelines in this book. I'm also going to recommend On Writing Well. Spoilers. 5b. The Elements of Programming Style - The Elements of Style + Brian Kernighan. I wouldn't recommend a book that I don't trust is really well written. That just wouldn't be me. I stand behind my recommendations.
on “My Top 100 Programming, Computer and Science Books: Part One” ↗…for the sake of being wordy. If you think the code is terse just to show off you are missing the point. There's a difference between writing obscure code and writing concise idiomatic code -- see "The Elements of Programming Style" by Kernighan and Plauger. I'd rather Kernighan, Ritchie, Thompson, Pike, et al. write my production code than someone who thinks C pointer idioms are a punishable offense. "That sort of thing" has been…
on “Learn C The Hard Way” ↗…writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?" -Brian W. Kernighan I read a book by Brian Kernighan a few years back, "The Elements of Programming Style" and for me it has so much good advice. The book may not be as relevant in the days of Ruby, C99 and the like, but valuable advice nevertheless. I wonder if reading the literature (countless books written…
on “I no longer understand my PhD dissertation” ↗…no worries. The individual refactorings are more-or-less interesting, but as others have said, they're somewhat commonplace now. Two books that every programmer should read: Software Tools[1] and The Elements of Programming Style[2] by Kernighan and Plauger. Bonus: The Unix Programming Environment[3] by Kernighan and Pike. [1] https://www.amazon.com/Software-Tools-Pascal-Brian-Kernighan... [2] https://www.amazon.com/Elements-Programming-Style-2nd/dp/007...…
on “Announcing the Second Edition of “Refactoring”” ↗There's quite a series of books co-authored by Kernighan, all excellent. Three others are The UNIX Programming Environment, Software Tools (in Ratfor and Pascal), and The Elements of Programming Style. They are classics for many reasons, including how far you get in such short books.
on “Technical Writing: Learning from Kernighan” ↗"write clearly -- don't sacrifice clarity for 'efficiency'" "make it clear before you make it faster" "make it right before you make it faster" "keep it simple to make it faster" From "The Elements of Programming Style" by Kernighan and Plauger Other than that maybe that naming is one of the hardest and most important things to do.
on “Among your lessons learned as a productive developer, which are the best?” ↗The Elements of Programming Style by Kernighan and Plauger Software Tools by Kernighan and Plauger The Psychology of Computer Programming by Weinberg A cartoon-illustrated DIY Honda Civic repair book from the 80's I no longer remember…
on “Ask HN: What are the most eye-opening textbooks you have ever read?” ↗Kernighan and Plauger's _The Elements of Programming Style_ covers exactly this ground, showing in turn poor code and how it could be better. They use real-life bits of code they come across, not artificial constructions. Kernighan and Pike's later _The Practice…
on “Ask YC: Could you point to examples of great and terrible code” ↗Not trying to sound cute, but The Elements of Programming Style by Kernighan and Plaugher (1974). Just read this last week during a day of plane travel. It's all PLI and Fortran, with lots of GOTO being harmful examples, but surprisingly much of it is still relevant.…
on “Ask HN: What's the best programming book you've read recently?” ↗I read The Elements of Programming Style early in my career, and in the context of the early '80s I remember it to be superb. And fairly short.
on “My Top 100 Programming, Computer and Science Books: Part One” ↗…bookshelf reserved for everything Kernighan, e.g. both Software Tools editions, both C Language editions, The Unix Programming Environment, The Practice of Programming, The AWK Language, even a copy of The Elements of Programming Style. I, and my employers and clients, may owe more to Mr. Kernighan for his teaching and programming style, than anyone else.
on “Ask HN: What language-agnostic programming books should I read?” ↗…about good coding practices and simply reading other developers' code, regardless of its quality. For example when I was in junior college a programmer-on-duty recommended I read Kernighan and Plauger's "Elements of Programming Style." Reading this style guide had an immense impact on me. Following that book, I discovered Kernighan and Plauger's "Software Tools" which illustrated important aspects of the UNIX philosophy (and good…
on “Ask HN: How do you get better at coding?” ↗…Microsoft Press, 1998. Maguire, Steve. Writing Solid Code. Redmond, WA: Microsoft Press, 1993. Ranade and Nash. The Elements of C Programming Style. New York: McGraw-Hill, 1992. Kernighan and Plauger. The Elements of Programming Style. New York: McGraw-Hill, 1982. Caner, Cem, et al. Testing Computer Software, Second Edition. New York: Wiley Computer Publishing, 1999. Hunt, Andrew, et al. The Pragmatic Programmer. Reading, MA: Addison-Wesley,…
on “Ask HN: What are the books you wish your colleagues had read?” ↗I've been enjoying "The Elements of Programming Style" by Kernighan and Plauger. Don't get put off by the references to Fortran, what they say applies to any language. "Structure and Interpretation of Computer Programs" by Harold Abelson, Gerald Jay Sussman,…
on “Among your lessons learned as a productive developer, which are the best?” ↗