3 ms·
The 'premature optimization is the root of all evil' quote is from Knuth's 1974 paper "Structured Programming With Go To Statements", p268, second column not "T
by eesmith 7y ago
The 'premature optimization is the root of all evil' quote is from Knuth's 1974 paper "Structured Programming With Go To Statements", p268, second column not "The Art of Computer Programming"
- nine_k 7y agoSometimes optimization is not premature: when you have a known performance problem, have done proper profiling, and see that it's a tight loop (as usual). Then you can shave off some execution time by using a slightly different construct, though bigger wins usually lie elsewhere.
- Ididntdothis 7y agoThat’s just optimization. Premature optimization is to use certain constructs that often make code more complex because you believe that they are faster.
- eesmith 7y agoSure. But that's not premature. Bear in mind that the given quote is only the most memorable part of Knuth's longer statement: > We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. > Yet we should not pass up our opportunities in that critical 3%. FWIW, I've read that Knuth attributes it to Hoare, and Hoare attributes it to Knuth. Looking now, I see that Knuth also wrote a similar comment in "Computer Programming as an Art", at http://faculty.salisbury.edu/~xswang/Research/Papers/turning/a1974-knuth.pdf http://faculty.salisbury.edu/~xswang/Research/Papers/turning... : > The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times; premature optimization is the root of all evil (or at least most of it) in programming. That was published the same year and month as the first paper, so I don't know which gets priority for any attributions.
- magicalhippo 7y agoIf you've got a known performance problem it's not premature. Knuths quote is the programming version of don't buy clothes for your baby before you've had sex for the first time. There are some important distinctions though, which gets lost if one takes the quote at face value without much context. For example, I think one should strive to avoid O(n^2) loops and similar unless one is absolutely positively certain n will forever be bounded to some sane value. My point being that O(n^2) code can make the application completely unusable, which makes it something more than a pure optimization problem.
- eesmith 7y ago(As an aside, some asexual people, who never had sex and are not interested in ever having sex, are still interested in adopting, and would buy clothes for their baby before having sex for the first time.)