Programming Pearls

Programming Pearls

Just as natural pearls grow from grains of sand that have irritated oysters, these programming pearls have grown from real problems that have irritated real programmers.

I just finished reading Jon Bentley’s book: Programming Pearls. I read this book after Scott Hanselman’s and Jeff Atwood’s recommendations.

The problems analyzed in this book are still actual. However, I think that today programmers face slightly different challenges. Most of the problems described in this book are already solved in the libraries, or not often existing anymore (e.g., pretty printing on the console). I read the 2nd edition published in 1999, and most of problems require update to nowadays environments. For example: variable naming suggest the need to save the memory. E.g., l, u, x.

int binarysearch1(DataType t)
{	int l, u, m;
	l = 0;
	u = n-1;
	for (;;) {
		if (l > u)
			return -1;
		m = (l + u) / 2;
		if (x[m] < t)
			l = m+1;
		else if (x[m] == t)
			return m;
		else /* x[m] > t */
			u = m-1;
	}
}

In the interview (“Epilog to second edition”), the author argues that programming style he used should not be used in large software projects. Let’s take this excuse.

Book overview

Part I is a set of useful, general advises how to tackle programming problems. One caveat: nowadays we use unit testing instead of assertions and “scaffolding” (described in chapter 5). However, it might be useful in some environments with some particular circumstances.

Part II is about performance. Chapter 6 describe different optimization techniques. Although the tips are useful, today we are doing optimization on higher levels. I wonder if at least 1% of today programmers would be able to improve program performance, by rewriting assembly code. Anyway, this chapter shows that performance improvements can be done on different levels: algorithms, data structures, system architecture, underlying software, and even hardware. I like chapter 9, where author presents some very sophisticated tricks.

Part III (Columns 11-15) is about algorithms. Although it shows interesting analysis and fundamental algorithms (for sorting, and searching), I would rather recommend some solid algorithms book (e.g. Introduction to Algorithms by Cormen et al).

Summary

Programming Pearls shows which parts of software development changed, during last 15 years, but some parts of this book still remain valid. Moreover, this book is a good history lesson showing by example the advancement in software and hardware.

This book has many references to Steve McConnell’s Code Complete, and The Mythical Man-Month. These books are on my to-read list for some time, and I will definitely read them in the near future.