Programming Pearls (Second Edition)
Choice and Precious
One definition of pearl is something "very choice or precious." Like the programming pearls it describes, Bentley's collection of essays has itself transcended the ordinary to achieve pearl status.
Originally published in Bentley's "Programming Pearls" column in Communications of the ACM, these fascinating essays were collected and revised in book form in 1986. Now revised 14 years later, this material has definitely stood the test of time. The first edition remains #2 on McConnell's Code Complete Reading List, and is listed favourably in an article on Great Books in Computer Science.
A Sense of Wonder
It was directly because of McConnell's Code Complete reading list that I, a few years ago, purchased and read Programming Pearls and its sequel, More Programming Pearls. Despite McConnell's effusive praise and corroboration from a colleague, I was not fully prepared for the experience.
I say experience, because that's what it was. It reminded me of reading Alice's Adventures in Wonderland [1] or Godel, Escher, Bach [2] (perhaps not coincidentally, also on the above list of great books in computer science). It filled me with a sense of wonder that is difficult to describe. It confirmed my love for computer science.
I believe that I am not alone in this regard.
What's New?
Twelve of the thirteen columns in the first edition have been edited substantially for this edition, and three new columns have been added. The new columns are on the topics of testing & debugging & timing, set representations, and string problems. This new edition is about 25 percent longer.
Although the first edition had been getting a little long in the tooth, the revisions once again place the essays in the modern world. Discussions of performance take into account modern hardware, caches, and instruction-level parallelism. Modern languages (C++, Java) are compared and contrasted where appropriate. Modern books (such as McConnell's Code Complete and Musser & Saini's STL Tutorial and Reference Guide [3]) are referenced and recommended.
Like Meeting an Old Friend
Re-reading this book was like meeting an old friend. Notwithstanding the major revisions, it has changed in subtle ways. Some anecdotes have been updated, some material reorganized. But it's still the same book. All of the energy and fun remains, youthful as ever.
I'm pleased to see that Bentley is still happy working at Bell Labs / AT&T / Lucent. Perhaps that's why this book is so great. There's a lot of intelligent people working there, and they put out some fine books. Bentley produces a Markov text generator in column 15, and compares it favourably to his colleagues' (Kernighan and Pike) version in the recent book The Practice of Programming [4].
Supporting Material
I must say that the supporting web site for this book (URL below) is excellent. It has all the information on why this book was updated, along with exactly what was revised. There the curious reader will find excerpts from columns, some problems and their solutions, and many other parts of the book available online.
All of the source code is available and free for use. Relevant web sites are linked and annotated. I love the Java applet that demonstrates sorting algorithms (source available!). Bentley even provides some overhead transparencies for use in teaching.
Recommendation
This is a no-brainer. I've always recommended reading this classic, and even re-reading it. The second edition is merely an excuse to purchase and (re-)read a revised copy. The time spent is well worth it. (Remember, only one column per sitting!)
I also recommend scrounging a copy of the sequel, which is out of print [5].
Purchase this book at fatbrain.
Links
Programming Pearls (Second Edition) Official Site
Programming Pearls (Second Edition) at Addison-Wesley
Programming Pearls (First Edition) at Addison-Wesley
More Programming Pearls: Confessions of a Coder at Addison-Wesley
Table of Contents
Part I: Preliminaries
1. Cracking the Oyster
2. Aha! Algorithms
3. Data Structures Programs
4. Writing Correct Programs
5. A Small Matter of Programming
Part II: Performance
6. Perspective on Performance
7. The Back of the Envelope
8. Algorithm Design Techniques
9. Code Tuning
10. Squeezing Space
Part III: The Product
11. Sorting
12. A Sample Problem
13. Searching
14. Heaps
15. Strings of Pearls
Epilog to the First Edition
Epilog to the Second Edition
Appendix 1: A Catalog of Algorithms
Appendix 2: An Estimation Quiz
Appendix 3: Cost Models for Time and Space
Appendix 4: Rules for Code Tuning
Appendix 5: C++ Classes for Searching
Hints for Selected Problems
Solutions for Selected Problems
Index
Notes
[1] Why do people (book sellers, web sites, bibliographies, etc.) insist on incorrectly calling this book Alice in Wonderland? It's not just for kids; Lewis Carroll was a mathematician, and it abounds in metaphor, puzzles, hidden treats. Read it. Accept only the John Tenniel illustrations!
[2] Godel, Escher, Bach: An Eternal Golden Braid is subtitled A Metaphorical Fugue on Minds and Machines in the Spirit of Lewis Carroll. It was reviewed on Slashdot: Godel, Escher, Bach (Review).
[3] However, use this book instead: Austern's Generic Programming and the STL.
[4] I reviewed this book for Slashdot: The Practice of Programming (Review).
[5] Why? I don't understand why some classics go out of print. I'm still trying to find copies of Artificial Life II, On Numbers and Games, Computation: Finite and Infinite Machines, and a host of others.
Programming Pearls is very cool. The nice thing about it is that really explains in detail some of the thought processes which lead to a programming being written the way it is; it very nicely shows the tradeoffs involved in choosing one approach over another.
... it'll be worth your time ...
The other cool thing is, that this really is a book for programmers. I appreciate Donald Knuth as much as the next guy, but his books are so mathematical, that I found myself skipping over more of the material, than I thought was good. Programming Pearls is the opposite: it clearly lays out the algorithms involved and often has nice drawings of the actual datastructures used. For a book of it's deapth it's pleasanly short, sparse in math and to the point. Read it, think about it for a while, program for a while and then read it again
I bought the 1st edition of this book not too terribly long ago, and before I had read a third of the way through it, I was using its insights in my code.
I was working on a series of General Ledger reports, and the first one? Well let's just say that I won't win any design awards. Somewhere in there I started reading this book and my code cleaned up dramatically. I can't say that the next report in the series will win any awards either, but I found myself sitting and waiting a bit before coding, and it has paid off. By the end of the project, my programs were almost elegant. I enjoy looking at them--and they aren't a nightmare for mods.
Just an example: The report before reading the book and the one right after are both variations of Income Statements. I needed to make a change that would affect both. Some of the code was in a joint library file, but some was in each report. The first report required at least a dozen places of change, the second required THREE LINES!
Granted, better design ideas from other sources were at work, and these were some of my first commercial programs, but this book definitely had an impact.
Buy this book, and take the time to ingest it. Work the programs--even if you think you understand them. It will pay off nicely.
At least it did for me.
We are agents of the free
Check out the books website for lots of little snippets from the book
Programming Pearls
-- Ed Avis ed@membled.com
Whether or not you buy the book, and whether or not you think of yourself as a programmer, if you consider yourself a thinking person, you should take this quiz. If you can't do back-of-the-envelope calculations, you should find this out as soon as possible, and fix the problem while you still can.
Babar
The problem I had with this quiz was that a lot of the questions assume American units and places. For example, I don't have a really good mental model of what weight a pound is, I don't know where Mississippi or Missouri are, and I've only heard of the Golden Gate bridge - I've never seen it.
How about some alternative questions:
This is a simple trivia quiz, not an estimation quiz.
Estimation is the process of making reasonable assumptions based on incomplete or limited data. You need to have some data to base your estimates on, however.
I could perhaps estimate the length of the Golden Gate Bridge or the weight of a Boeing 747, but only if I had a frame of reference. As I have only seen the GGB in artistic visuals not intended to give a sense of scale, and I have only seen a 747 in Hollyweird movies, I couldn't provide a worthwhile estimate for those.
I happened to know that the Shuttle orbits in about 90 minutes, and that roughly 50 people signed the Declaration of Independence, so I did well on those. But the significant factor here my knowledge of trivia, not estimation skills.
A true test of estimation would be to give you various pictures of things, with a known quantity for scale, and ask you to figure out dimensions, weight, volume, etc.
dragonhawk@iname.microsoft.com
I do not like Microsoft. Remove them from my email address.
John Markovich is a photographer based in Minneapolis, MN...
If you're not part of the solution, you're part of the precipitate.
Charles Lutwidge Dodgson (better known as Lewis Carroll) did not make up Alice. Alice was a real girl, full name of Alice Pleasance Liddell, and Dr Dodgeson is widely believed to be a paedophile.
There is no evidence that he ever consummated his relationship with young Alice, he was quite proper about it and all, but you can judge his interest from the fact that he took pictures of female children (including Alice) as scantily clad as he could arrange and eventually proposed marriage to Alice.
For some reason this gets glossed over in a lot of places...
Regards,
Ben
My usual seat in the cluetrain is at A HREF="http://pub4.ezboard.com/biwethey.ht
Although it does make reading the book a very different experience.
The book is based on short stories that he told Alice + other female friends to keep them interested in him. Alice (at the age of 7) is the person the story is being told to. The Red Queen appears to be based on the chaperone. So on and so forth.
So while you can read the book without knowing the background, the background definitely affects how you interpret the book!
Regards,
Ben
My usual seat in the cluetrain is at A HREF="http://pub4.ezboard.com/biwethey.ht
Not my page... interesting mistake, though.
-- Ed Avis ed@membled.com