Book review: “Programming Pearls” by Jon Bentley

September 12th, 2008 at 11:23 am

Programming Pearls is a collection of columns that the author has published in the Communications of the ACM journal. The topics of the columns cover many aspects of programming, like debugging, algorithms, efficiency and data structures. Each column is about a different topic, in which the author usually presents a problem and then gradually builds several solutions, discussing their relative merits.

I think that what describes this book best is two quotes from it. One from the epilog:

The most important [theme] is that thinking hard about programming can be both useful and fun.

And the other from section 12.3:

One part of a programmer’s job is solving today’s problem. Another, and perhaps more important, part of the job is to prepare for solving tomorrow’s problems.

It’s a fun book to read for any programmer, and I highly recommend it. The only problem with it is a somewhat sub-optimal programming style, in C and especially C++ (what’s with all this horrid C++ in books about algorithms?). But all in all, it doesn’t ruin the overall pleasant experience.

Related posts:

  1. An important part of a programmer’s job
  2. Book review: “Win32 Perl Programming: The Standard Extensions” by Dave Roth
  3. Book review: “Expert C Programming” by Peter van der Linden
  4. Book review: “Extreme Programming explained” by Kent Beck
  5. Book review: “C++ GUI Programming with Qt 3″

11 Responses to “Book review: “Programming Pearls” by Jon Bentley”

  1. AlbinNo Gravatar Says:

    Constructive Criticism: Your “review” doesn’t have much substance other than two quotes from the author, and the fact that you liked it.

    Maybe you should expound on the parts you liked best, what you learned from it, who might benefit from reading it, how it challenged you, did it change your thinking, etc.

    This post is a waste of the reader’s time who is looking for a real review, and I believe you can do better.

  2. elibenNo Gravatar Says:

    Albin,

    Thanks for the comment - I completely agree with you.
    However, sometimes I just don’t have the energy to compose long reviews. In such cases, I have two options: either post no review on the specific book, or write a very short one, like this. Mostly, I prefer picking the second option, because IMHO even the short notice of whether I liked the book or not has some substance.

  3. Vasudev RamNo Gravatar Says:

    Nice review, Eli.

    I think it should be useful for anyone who hasn’t read Programming Pearls.

    I’ve read it, as well as the sequel - More Programming Pearls. Both the books are quite good.

    One of them (don’t remember which, and don’t have the books at hand right now) has got some very good examples on powerful uses of awk, particularly on the associative arrays feature of awk - those examples would take a lot more code and be more difficult to write in most procedural languages like C.

    - Vasudev

  4. elibenNo Gravatar Says:

    @Vasudev
    It probably appears in More Programming Pearls, because I don’t recall that part. Anyhow, the usage of awk is typical of the book’s age :-) I suppose I’d use Python now.

  5. Vasudev RamNo Gravatar Says:

    Hmmm … personally, I wouldn’t consider awk outdated at all, nor would I blindly use Python instead of awk for all possible needs - that would be like reinventing the wheel :-) - see below for why. It depends, among other things, on what problem you’re trying to solve and what and how many tools you have in your toolbox. For people skilled in UNIX/Linux and the wizardry that’s possible at the shell prompt and in shell scripts, awk is sometimes a better tool, to integrate into a powerful pipeline of commands, because of its better integration with the shell and UNIX than that of Python. But you need to grok UNIX/Linux pretty well to leverage that - not everyone does.

    Awk is not ‘just’ a language with associative arrays, a.k.a. Python’s dictionaries. It has a lot more to it than that. Though it’s a specialized ‘little language’ (google for the term) - versus Python being more of a general purpose language - awk excels in its area, IMO.

    And even if used standalone (i.e. not within a shell script or within a pipeline at the shell prompt), awk gives you a few things for free that Python does not. One such example is the automated implicit loop over all input filenames passed on the command line. In Python, you’d have to write your own code for that - which is not a big deal, it’s simple code to iterate over all the files and pass them to a chunk of code that processes each file, but then, every additional line of code you write means more code to test, debug, maintain, …. and so on; and when you multiply that effort by many such scripts, it can add up. Ok if you’re a hobbyist programmer or have all the time in the world, but otherwise …

    Also, awk lets you refer to the current field number, the current field value ($i - replace i with 1, 2, 3. etc.), the current record as a whole ($0), and and the current line number (NR) and file name (whether or not you have 1 or many input files), more easily than Python does.

    Perl has command-line options (-n and -p, IIRC) to do that kind of automated loop over the input filenames, but Python does not, at least not without some library (as far as I know) - and I just checked its command-line options help.

  6. elibenNo Gravatar Says:

    @Vasudev

    I agree about using awk as part of the command line piping, if you’re proficient in it. However, I would strongly recommend against using it for anything else, like stand-alone scripts.

  7. SRJNo Gravatar Says:

    “what’s with all this horrid C++ in books”

    Do you mean:
    1) You dislike all C or C++ code, simply because of the language - you’d rather see Python, for instance
    2) The book does a bad job of coding in C and C++ - you’d rather see better C and C++ code

  8. elibenNo Gravatar Says:

    @SRJ,

    It’s (2), definitely.

  9. EricNo Gravatar Says:

    C++ is very difficult, or so I’ve heard. Would you suggest learning another language like PHP first?

  10. elibenNo Gravatar Says:

    Eric,

    If you’re just learning to program, definitely don’t go for C++. Neither should you begin with PHP - it’s not a language that’s good for beginners.

    I personally recommend Python. You can begin with any of the freely available basic programming wiht Python books online, depending on your age and requirements. This looks like a nice book to begin with if you’re young.

  11. ripper234No Gravatar Says:

    I have to recommend java/C# as well - they’re of the C++ flavor, but without many of the problems. And they are strongly typed, which I personally can’t live without.

Leave a Reply

To post code with preserved formatting, enclose it in `backticks` (even multiple lines)