Tuesday, February 3, 2009

Reading Knuth

I've been reading a little Knuth for the past couple of days. I've read about the famous statement, "premature optimization is the root of all evil," many times, and yesterday I decided to read his statement in its whole context. You can find Knuth's whole article here (thank you, Wikipedia):
Knuth, Donald: Structured Programming with Goto Statements. Computing Surveys 6:4 (1974), 261–301.
I want to quote the passage for you that contains the famous line about premature optimization. It's on page 268 (the eighth page of the article):
There is no doubt that the grail of efficiency leads to abuse. Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.
Most people stop here when they quote Knuth. But actually, it just keeps getting better:
Yet we should not pass up our opportunities in that critical 3%. A good programmer will not be lulled into complacency by such reasoning, he will be wise to look carefully at the critical code; but only after that code has been identified. It is often a mistake to make a priori judgments about what parts of a program are really critical, since the universal experience of programmers who have been using measurement tools has been that their intuitive guesses fail. After working with such tools for seven years, I've become convinced that all compilers written from now on should be designed to provide all programmers with feedback indicating what parts of their programs are costing the most; indeed, this feedback should be supplied automatically unless it has been specifically turned off.
What a beautiful expression of the idea that's at the core of what I do for a living.

If you haven't seen "For Developers: Making Friends with the Oracle Database" yet, I hope you'll take a look. My aim is to help Oracle application developers writing Java, PHP, C#—or anything else—understand how to find that critical code that Knuth wrote about in 1974. ...And, just as importantly, how to ignore the other 97% of your code that you shouldn't be worrying about.

3 comments:

Dave Edwards said...

You want the Knuth? Can you handle the Knuth? Cary Millsap can. Now reading Donald Knuth might seem like a backward approach to making things simpler, but Cary found that Knuth’s formula, “premature optimization is the root of all evil,” may be helpful even to database programmers.

Log Buffer #134

Cary Millsap said...

(grin) Thanks for the ref, Dave.

–Cary

Epic said...

Wow Cary! That was quite the story telling! Im quite amazed at all the things you've done! No wonder your soo happy! Well I hope you had your fun and excitement. In the mean while, as winters kicking in right now, we might be expecting some change! A change in weather hopefully to the better :} I dunno, some how reading about what you wrote makes me remember things that I never thought I would have ever remembered, funny how that works doesn't it??
IBM laptop lcd screen repair


-Much LoVe