The Practice of Programming
Brian W. Kernighan | Rob Pike


Compras Nikon
Bluetooth
Coauthored by Brian Kernighan, one of the pioneers of the C programming language, The Practice of Programming is a manual of good programming style that will help any C/C++ or Java developer create faster, more maintainable code.

Early sections look at some of the pitfalls of C/C++, with numerous real-world excerpts of confusing or incorrect code. The authors offer many tips and solutions, including a guide for variable names and commenting styles. Next, they cover algorithms, such as binary and quick sorting. Here, the authors show how to take advantage of the built-in functions in standard C/C++. When it comes to data structures, such as arrays, linked lists, and trees, the authors compare the options available to C, C++, Java, and even Perl developers with a random-text-generation program (using a sophisticated Markov chain algorithm) written for each language.

Subsequent sections cover debugging tips (including how to isolate errors with debugging statements) and testing strategies (both white-box and black-box testing) for verifying the correctness of code. Final sections offer tips on creating more portable C/C++ code, with the last chapter suggesting that programmers can take advantage of interpreters (and regular expressions) to gain better control over their code. A handy appendix summarizes the dozens of tips offered throughout the book.

With its commonsense expertise and range of examples drawn from C, C++, and Java, The Practice of Programming is an excellent resource for improving the style and performance of your code base. --Richard Dragan


1 OK, but there are way better books out there
Unfortunately, this book didn't give me much. It more or less is a extract of scattered wisdoms found in Steve McConnells "Code Complete" and Jon Bentleys "Programming Pearls." A lot of the examples and ideas brought forward in "The Practice of Programming" seem to be taken more or less directly from those books. I highly recommend getting the original works instead, as they are more complete, in-depth and also present a more consistent and enjoyable read.
2 One of those books that will make you a better programmer
Simplicity, Clarity and Generality are indeeds the qualities of fine code. This is one of the few books that strives to make you a better programmer. Most books are about how-to, this is a book that goes beyond that and gives you information that can make you better. The other two books that do this for me are "Programming Pearls" by Jon Bentley and "Refactoring: Improving the Design of Existing Code" by Martin Fowler.

The pedigree of the authors is something that you should not dismiss lightly, after all, Brian Kernighan is the "K" in the K&R book, and also with Rob Pike the author of "The Unix Programming Environment".

Lots of good stuff.
3 Experience distilled into a book
This book is perfect, it's not really for beginners, but more for someone crossing over to an intermediate level of programming, and wishes to learn some golden rules to keep in mind while programming.

The book is written in an incredibly simple and straight-forward way, which makes everything incredibly simple to grasp, and memorable. I know more than a handful of UNIX programmers that all either keep this book on their desktop for reference, or read it at least once a year.

This is the book I'd recommend to anyone who wants to "program better", this book probably won't teach you any new techniques, but it will teach you how to make your code more solid, more readable, and more enjoyable to maintain/debug.


4 A guide for real programmers
This book helped me get beyond individual languages, op systems, and tools, into the heart of programming.
It's about solving problems and about getting clear on what I am doing before I start pounding the keyboard.
The sections about specific languages are useful, but not nearly as interesting as the general topics.
The sections on debugging are specially helpful.
5 Good text, but take with salt
The text of the book is good and gives some very good advice about programming. But it is important to realize that they are only suggestions, and should sometimes be disregarded.
6 Great book for intermediate programmers/hackers
This book is basically all the "common sense" stuff that you learn after programming for years and years.. most proffessional programmers already know this stuff--or should! This is a perfect book for a college graduate who is good, but needs some pointers in the real world, or for those who just want to freshen up their skills, etc. Beware though, this book is not "Programming for Dummies" you must already be well familiar with C/C++ and some algorithms and data structures to fully understand what the author is trying to convey, at times. But even if you don't, it's still a great book... it is (or will be) one of those classics like The C Programming Language, which every programmer has on their bookshelf. Pretty much any book written by Kernighan or published by A-W (Professional series) is a worthwhile read...

In a nutshell, as they say in the book: this is what most people should have learned in college, but couldn't or didn't. Get it if only to read the first chapter on style... I for one hate rewriting or reading people's code who didn't know how to write it well/clear, or comment it well.


7 stuff that matters
For the facts I have nothing substantial to add to the January 2001 reviews.

I do programming since 1983. Started with Fortran, Pascal, Modula 2 and C. Read Bertrand Meyer's "O-O Software Construction" which opened my eyes how to design interfaces. I created code and rewrote code. I worked together with programmers of many kinds of personalities.

Comparing my experiences with what Kernighan and Pike's book tells is, that this book really discloses the fundamentals of effective software development to produce maintainable software systems:

simplicity, clarity, generality.

And working with programmers who are on the way to discover or yet have discovered these pearls of wisdom is fun!

BTW: "The Pragmatic Programmer" written by Andrew Hunt and David Thomas is another great book to consider.


8 Good software engineering tool
This book is a great concise text on good software engineering and programming practices. It touches on pretty much all the aspects of planning a software project, as well as writing good, professionally done code. The examples are relevant and certainly help to reinforce the writing.
However, this book is not for anyone who has taken any serious amount of Computer Science/Engineering classes, or has worked in a serious software engineering position for even a year or two. As I was reading it, I found that it was all good information, but that I pretty much already knew most of what was said.
I would hestitate to call this book 'basic', but I think that it's aimed at people who are still developing their coding and engineering skills, and not meant for those who are trying to "touch-up" or perfect them (to the extent that that is possible). By that same token however, plenty of people who have a college degree in computers or work for a software company write bad, unprofessional, not-well-tested code. You should seriously evaluate your own competence and practices before you decide to pass or purchase this book.
The only other note is that the very last chapter on notation seems to be written at a level much higher than the others. It didn't really seem like it fit in too well with the tone and pace of the rest of the book.
9 Compare it to Code Complete
This book has all the details of Code Complete, but in 1/4 of the book. It is a really good book.
10 Entertaining reading
This book won't teach you how to program. It won't teach you how to solve that one problem you've been struggling with for days. It won't revolutionize your programming practice. It will, however, be entertaining reading. Pike and Kernighan obviously have a story or two to tell, and they relate to them in their suggestions for programming practices. For anyone with practical experience most things will be fairly basic and obvious. No one is ever a complete programmer though, and there are tidbits you will pick up here and there.

I would mostly recommend this book to someone who enjoys reading a little bit of entertaining computer history and like to hear about Kernighan's and Pike's own experiences in becoming experts of programming.


11 an excellent book
addison-wesley's computing series never fails me. and this book is not an exception. just as the author advocates, Simplicit, Clarity, and Generality are very important in our practice of everyday programming. but regrettably, most of us don't pay much attention to these 'minor' aspects. i find a lot of tips in this book are very useful. and to raise a good programming habit is invaluable. in short, this book is one of my favorite in computer books. (nearly all my favorites come from Addison-Wesley). but i got a little confused about the markov algorithm described in chapter 3. can any experienced programmer discuss it with me? your help is much appreciated.
12 Out of focus
Sometimes even the greatest masters make minor works. Brian Kernighan is a master. And this book is a minor work. Why? Take a look at the TOC. It refers to, at least, 5 complicated topics wich deserve nothing less than a single book each one. How can someone cover decently them all in just one 267 pages book? Once you finish each chapter remains the feeling that it was just a glimpse, far from a good explanation.

It's certainly an above the average book. The authors know what they are talking about. But you would be much better served by the suplementary reading at the end of each chapter. At least, they sugest you the really good books.

This is also an Unix biased book. Kernighan and Pike don't like interactive debuggers. And they don't care too much about user interface. If you are on the Windows/Mac/Palm/etc side of programming, you'll probably see things a little diferently.


13 Pearls of Wisdom
There are a number of tips that a programmer can take away from this book. The highlights of this book have been pointed out by earlier reviewers, so let me just mention one thing.

Any philosophical person knows that knowledge can be taught and transmitted, but not wisdom. This book has, by the authors' own admission, been written on the basis of years of personal experience: good and bad. They are wiser because of that, but have they been succesful in transmitting that WISDOM to their readers? I am confident they have not been.

One cannot "learn" something unless he has experienced it himself. This is a fundamental tenet of Eastern philosophy. The reviewers who are so appreciative, if they are truly so, are so, because they personally relate to the words of advice given by Kernighan and Pike. A person who has just been introduced to function macros neither understands nor appreciates the fuss the authors make over the usage of these constructs. On the other hand a user who has already been bitten by the bug would have felt "Aha! how wise! They are perfectly right!"

In summary, my theses is that this is a good book, but if you are a novice programmer who expects to quickly get wise by reading this book, it may not be possible. Note, however, that I would say the same damn thing of all books in this genre: writing solid code and other books in the microsoft press stable.


14 Simple and excellent
I am bemused by the disparaging comments of my fellow readers in regard to this book. Kernighan and Pike make clear their intent in the first paragraph of the preface to this book; it is about simplicity, clarity, and generality.

To be sure, there is tinder here for short tempers and delicate egos. If you're under the gun, trying to duct-tape together the fifth release of some huge, unwieldy application, this book does not contain the short-term quick fixes you've been hoping for. If you're righteously convinced of your own sound practices and don't care to look at someone else's methods, this book may irk you.

Kernighan and Pike have written a book about the most basic habits and outlook that a programmer should have. They have not tried to address all facets of programming. Instead, they sacrifice scope to make their points stand out all the more clearly.

Would this be a better book if they had cast their net wider? Hardly. If you start off by applying the carefully thought out, methodical approaches described clearly throughout this book, your code will still hit abstruse bumps and strange circumstances. But most problems will succumb to the same analytical ways of thinking and tools that Kernighan and Pike have laboured to describe with such clarity.

But don't imagine that I think this book is perfect; the authors have been doing many things in the same ways for a long time. Most often, this is because their methods are effective, but sometimes they are far too close to being cop-outs. For example, the idea that it's OK to just print an error message and bomb out if something goes wrong is laughable outside of the Unix command line environment, and is rarely appropriate even there.

Fundamentally, though, if you can't solve the problems at the ends of the chapters (they're easy), or you think you can't possibly benefit from reading a book that troubles to describe quicksort (which you probably learned in CS-201), then there is likely nothing for you here. At least until you think to question your perspectives. Until then, I'll confess to a sense of relief that I don't have to work with you :-)


15 Other choices are better
This book would have been fine 10 years ago. However, the topics covered here are better covered elsewhere, by other authors (Code Complete and The Pragmatic Programmer). There's very little in this book that is not covered in the other books, and combined, they covered more areas better.

In short: Better value can be found elsewhere.


16 Excellent book on programming

This is a very well-written and interesting book which covers many aspects of programming, including algorithms, debugging, testing, performance, portability, design, interfaces, style and notation.

The book's major strength is that the examples given are sufficiently deep to be useful and educational. There are many good exercises given for the reader to explore further programming concepts. Some of the mini-projects that are discussed include pattern-matching, a library to deal with data in CSV format and program that uses a Markov chain algorithm to generate readable prose.

One minor flaw in this book is that almost all of the examples are written in C, C++ or Java, whereas the title of the book suggests a more generic approach.

I'd recommend this book without hesitation to someone who has been programming for 2 or 3 years and wants to really improve their productivity and add a level of professionalism to their coding and program design.


17 Snappy Reading and Excellent Advice with One Shortcoming.
Hi,

This book is great for programming style and clarity but there is a glaring flaw: The authors have a bad case of six (or eight) letteritus when it comes to variable names. Even though they advocate readable names for globals and functions, they still change "procedure" to "proc", "SIZE" to "SIZ" and "buffer" to "buf".

Other than that it is a good book.


18 Should be called The Practice of Programming in C
This book is way too C-centric for me (I do Perl pretty much exclusively). A lot of discussion of topics like memory management and such that is not terribly interesting for many programmers. In addition, most of the material seemed like the kind of thing a decent programmer will pick up on the job after a year or two if they are any good.

That said, this would probably make a great text for students in school who don't have much experience dealing with large, evolving projects, no matter what their preferred language is.


19 A hypocracy?
It seems that at least one of the author (Brian W. Kernighan) plays a hypocracy here. While he's advising about clarity (easy-to-read programs), he himself created tens of very difficult names for C functions, file names, constants and variables; and he DID NOT APOLOGIZE for it, BEFORE giving so many advices in this book. Brian should at least apologize for inventing these (among many) names : execve, execlp (and many other various names for function to execute programs), printf, scanf, longjmp, ls, ln, lp, etc, etc. He should mention what ve in execve, what lp in execlp, and so on (for various exec). He should apologize for making printf and scanf (print and write is better), longjmp instead of longjump (why you so ugly in removing the 'u'?), ls instead of list (4 is not too much), alias (or link) instead of ln, and print (or printer) instead of lp.

I also disagree with advice of style like this

if (cond) { block(); }

In my experience, this is better

if (cond) { block(); }

Many of the advices in this book have been proposed (in separate books) by many authors.


20 No waste of time here
In computing, the learning curve is doubly steep. Not only do we have to learn very complex operations, but we have to learn them at a pace unrivaled in any other field. Furthermore, the equipment improves at a rate that simply boggles the mind. In this frantic environment, we rarely have time to read our code twice, much less read a book about code. Therefore, when we do read, we must make every minute count. This is one book where your count of wasted minutes would be a very small one.
Some of the tips in this book are obvious in retrospect, yet ones that you probably would not think of. My favorite is the fact that due to the changes in processors, a double precision floating point arithmetic operation can be faster than the equivalent one for integers. In the "old" days, the gospel was that you must avoid floating point operations unless absolutely necessary, to avoid the degradation of performance.
Other tips, such as methods to assure you comment what is necessary, taking a few minutes to learn simple performance features, debugging and testing guidelines; portability issues and basic algorithm analysis should cause you to pause for a moment. Even in our hectic development environments, stopping and analyzing your code is a necessity.
It is difficult to conceive of someone who will not find a tip in here that will justify the cost of the book. Unless of course, you are one of the authors. I listed it as one of the top books of the year in my On Books column that appeared in the September, 1999 issue of _Journal of Object-Oriented Programming_.
21 Lots of useful thoughts
I've never regretted when I bought a book written by B.Kernighan. This is not an exception.

The book doesn't teach you any particular languages or algorithms. It just shows how to write good programs.


22 Wonerful book
If you buy one book on general programming practices, make this it. It is extremely good.. I learned a lot about how to create good, maintainable programs without many bugs, and many ideas on good design for performance as well.
23 Great Book I Got It For An Advanced C Class
This is the BEST programming book I have read right next to Teach Yourself C in 21 Days. I use this book when I program with C, I apply when using other languages also. I have never seen a book that teaches you the basics of everything. It should come with every developer tool on the market. I have recomended this book to every programmer I know. It is now my new bible.
24 A book that is full of wisdom and real world examples.
When the book was published I liked the title and knowing the authors assumed it would be a good book to have. The emphasis is more on C, less on C++ and Java and OOP in general. The chapters: Debugging, Testing, Performance and Portability describe real world examples and in concise way points out important practical aspects of software development. It is useful for practicing programmers with C,C++ or Java background. It is complementing what most other books do not cover. That is why I bought it. It is worth the price. Would be happier if the book covered the OOP traps and pitfalls more deeply.
25 INCOMPLETE
This book is a too fast made booklet to treat such a delicate argument. The Java examples seem a last minute add. A lot of important arguments are not present. I cannot substitute the book"Code Complete " with this one.Absolutely not.
26 Concise, well written, full of good and long-lasting advice.
I was surprised by some unfavourable reviews of this book, but they were probably by people expecting something different. This is not a handbook or cookbook. This book is about how to do things wisely... it is about long-lasting principles about how to program in practice. It is not a book about how to program in the latest version of a given compiler and windowing system.

I am not a professional programmer, but I do a fair bit of programming and lately software design for our research work. I have also read some of the earlier books by the same authors. Not everything was new to me, but nontheless it was never boring reading...

I do not mind paying for a book full of ideas, and few instructions. This is a book I will not open every day, but having read it has made me a better and wiser programmer every day.


27 I liked it.
I have been teaching myself programming for the past few years, and the programming books I've read teach specific languages. This is a general programming book that teaches concepts that I could not learn anywhere else. Obviously, if you already understand the information in the book before you read it, you will not profit from it, and, from what I understand, it does not break new ground. I think it is a pretty clear and concise introduction to the language-independent parts of programming, such as data structures and algorithms. I'm not ready for the Knuth books yet, and this book was a nice introduction.
28 We need to teach this to undergraduates
All too often our undergraduate students are left to learn programming by themsleves. The universities do a very good job of teaching algorithms, theory and special parts of "systems" (compilers, operating systems) but we rarely see any book that guides the student from the introductory courses to more advanced programming.

This is not a book about tricks or tips. It is a systematic exposition of various topics that are needed in practice. This is mmuch more than the earlier "Elements of Programming Style" by K and Plauger. It contains, for example, a chapter on profiling. No doubt every reader will have a list of topics that they would like to see included but the topics that are there are vital and very well treated. I hope that we will be able to teach a course based in part on this book at McGill.


29 For new coders a five star, for old timers a one.
If you've been around the block a couple of times don't waste your time. If however you are new and would like to see what's in this field do read carefully for the book contains many gems. Well written and carefully prepared.
30 Doesn't go beyond the basics
I really wanted to see more on software engineering, testing tools, etc. I think this book, if done well, would have been a huge tome. Instead, it is not a very insightful book for an experienced programmer. While it would be very useful for a novice or intermediate programmer, I'd have to recommend Code Complete over this one.
31 A waste of time
This book would be great if you want a review of what state-of-the-art programming in the 70's was like -- the Java snippets (which look like they were added as an afterthought) not withstanding. The book's coverage is as moldy as the many C language examples it presents (come to think of it, the only good I got from this book was a refresher in how badly designed C was).

If you want a real "Practice of Programming" book read McConnell's Code Complete.


32 Reasonably well-done but nothing new
If you have not read Steve McConnell's books this book is worth reading. The supplementary reading lists at the end of each chapter are valuable (again, if you have not already read the material cited). I was disappointed in the lack of new material and/or fresh perspective on older material. Read McConnell, Stroustrup, Lakos, Gamma et al, and Scott Meyers and skip this one
33 A Disappointment
I always have high expectations of Kernighan and I am not satisfied with this book. The writing is good, but the scope and depth of the content are questionable. The notion of "program" as portrayed in this book does not reflect the state of the art. There is no meaningful coverage of software reuse, adaptation, and evolution. There are no discussions on orthogonal aspects of development and deployment. If you write code that is to be configured and composed by persons other than yourself -- and code that does not have the unrealistic luxury of printing an error message (to what?) and exit (to where?) -- you should look elsewhere for serious help.

More generally, this book is indicative of the scaling problems of Computer Science education. If one picked up a book entitled "The Practice of Woodworking" that took an approach similar to Kernighan's, one would not expect the book to address issues related to professional carpenters and house architects. In computer books, the vast differences between a "paper boat" program and an "aircraft carrier" program are not always honestly clear.


34 Worth the money, but problems.
I found the book enjoyable. Best parts are stories of the old days, and some good chunks of code. Bad things: 1. Apparently written to "cash-in" on trendy lore-of-programming books ("Code Complete" etc.). 2. Chapters end with exercises that *aren't answered*. Even on their web page; some are obviously speculative but some clearly have correct answers which I thought I was paying-for when I bought the book. 3. So I'm stupid: the Markov chain chapters left me confused about the algorithm itself. 4. The C++ Java "interface" etc. stuff seems tacked-on to a basically C-language orientation (see #1 above). There is virtually *no* treatment of GUIs. This could be a plus of course.

But I still enjoyed the book....


35 A great book if you want to be a professional programmer
There is no doubt, this is a good book. In my opinion it focuses on the right aspects of programming and it does it in a concise and enjoyable way, and even better it does it on about 250 pages only. So, in fact I can manage to read it during hectic working days, not just buy it and decorate my bookshelf with it. I would recommend it to any beginner who wants to turn into a professional programmer. For the professionals who have been in the game for some years, it works very well as a reminder of what we should focus on to stay professionals. However, I feel it lacks something on how to handle really big software systems. But, together with the books by Steve Maguire and The Mythical Man-Month by Frederick Brooks, I would say you have a very good ballast as a professional programmer.
36 Good for pros, Great for beginners
As seen below, ego-scratchers will complain that this book doesn't cover any new ground. However, this book is an excellent resource for software engineers of any skill level. Things I liked:

The code isn't "baby talk" code like many books-- the examples have some real meat on them.

Also, the description of quicksort in chapter 2 is the best one I've ever read.

So, if you're the greatest programmer in the world, go write your own book. Otherwise, get this one.


37 Fantastic
Though i havent seen the final version of this book, the beta that i have read was fantastic. Particularily the sections on debugging and testing code.
38 A major disappointment
After reading all these rave reviews, I bought the book, expecting gems. Instead, I got a bunch of boring aphorisms and silly rewrites of programs that are long in the tooth. If you've had anything but the most banal of computer science education you have already outgrown this book.
39 Best book of its kind
I've long recommended Pike's "Notes on Programming in C" on my web page. This book includes most of the content from that essay and much more, but is still thin and concise.

What I like most about this book is that they justify all of their recommendations, show both good and bad examples, and keep the discussion grounded in actual code (rather than abstract principles).

Other things I liked:

- begins with a discussion of programming style and aesthetics

- they critique some of the designs that they have been involved in, such as C's stdio and string handling libraries

- they discuss the unique design issues presented by library design

- they give examples in C, C++ and Java, and give an honest appraisal of the tradeoffs involved in each language.

- FINALLY, excellent single chapter descriptions of systematic approaches to debugging and testing!

- they face up to some of the tough design choices that must be made outside the UNIX Ivory Tower (rare for these authors). For example, they sacrifice UNIX consistency in one application so that the application will behave consistently across UNIX and Windows.

Minor gripes:

- still skirts around tough design issues in error recovery and reporting; they advocate the "print a diagnostic and exit" approach (which is totally inappropriate for library code), and don't discuss the tradeoffs

- a few of the principles they cover will be trivial or obvious for experienced programmers


40 Best General Programming Book in Years
The book covers topics such as style, design, interfaces, notation, debugging, testing, performance tuning, and portability. Each of these topics gets its own chapter and is covered pretty throughly.

The writing is generally very interesting though at times it does get a little too much into details. It must have been interesting. I have finished reading it in less than 24 hours after having received it. This is something I've never done with a computer book before!!

The book does live up to its goal. I think any programmer (even with 20 years of experience) who reads this book will gain something from reading it.

Before you think that I think the book is perfect, I will point out some areas where I think it could be improved. First, I think the book is too focused on C. This is not surprising given that Kernighan is one of the authors. Personally, I have always believed that C is a language that encourages bad programming practices. In a few places in the book, I see some of those in the code that is presented. The other area I was disappointed in was that there was not much on object-oriented programming practices. Beyond that, I saw something I do not believe should be in any good OO program. That something was a public instance variable. A few places I disagreed with the authors on style issues. However, all of these problems are fairly minor and will hopefully be corrected in the next edition.

In conclusion, I think this is a book that all programmers should read at least once. I know I will keep my copy on my shelf for those times when I have questions like "how can I optimize this code?". It really is the best general programming book that has been published in years.


41 A pragmatist's dream
This book conveys that languages may come and go but time honored design principles and techniques will always remain the foundation for solid systems. A wonderful book for both novice programmers and experts alike.
42 Turns average programmers into great programmers.
This sort of book is long overdue. When I was a kernel hacker at Sun, Bill Shannon was the person who passed on the information which Brian and Rob have so carefully written down. It's very rare to see this sort of book - much of the material is quite subjective in nature, but my opinion is that it is ``correctly'' subjective. In other words, it suggests ways of doing things, which is always controversial, but the ways that they suggest are essentially the time honored traditions found in every experienced Unix kernel programmer.

Sunday, 07-Sep-2008 23:54:47 CDT
Quote of the Day:


FORTUNE'S RULES TO LIVE BY: #23

Don't cut off a police car when making an illegal U-turn.

All great ideas are controversial, or have been at one time.