5 ms·
Sigh, here we go again. > Tony Hoare's famous maxim "Premature optimization is the root of all evil." It's actually from Donald Knuth and this quote is freque
by lkjflakjsdeowe 3y ago
Sigh, here we go again.
> Tony Hoare's famous maxim "Premature optimization is the root of all evil."
It's actually from Donald Knuth and this quote is frequently taken out of context to argue against optimization in general.
Here is the entire quote
"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%."
The point is to spend time optimizing where it will have impact.
- karmakaze 3y agoKnuth attributes it to Hoare, and Hoare attributes it to Knuth. So it come's down to who you want to believe. Probably best to attribute it to both. My guess would be that Tony said it first, Knuth refined and printed it. It's always good to have the longer quote which gives needed context.
- eesmith 3y agoHoare attributed it to Dijkstra. See https://hans.gerwitz.com/2004/08/12/premature-optimization-is-the-root-of-all-evil.html https://hans.gerwitz.com/2004/08/12/premature-optimization-i... . "I’m sorry I have no recollection how this quotation came about. I might have attributed it to Edsger Dijkstra."
- karmakaze 3y agoSomeone needs to make a Spider-man meme with the quote.
- zelphirkalt 3y agoMaybe it is in the end a secret deal between them, to have a joke about circular references. ; )
- preommr 3y agoAlso people forget that quote is from the 70s. Almost 50 years go. Programming used to be very different from what it is now. "Premature optimization" wasn't "hey just use this popular lib cause it scales", it was "let's use some impossible to understand bit fiddling algorithm that only works on this piece of hardware".
- bluGill 3y agoIn any compiled language your optimizer will do all those weird things for you, and will even handle all the different generations of CPUs for you. Compilers never give you a better algorithm if you write the wrong one. Almost all languages have a standard library that has all the normal algorithems you would want, and where something wierd is better they have that done for you.
- eesmith 3y agoCompilers can and do replace some (simple) algorithms with a better one. At https://stackoverflow.com/questions/74417624/how-does-clang-generate-non-looping-code-for-sum-of-squares https://stackoverflow.com/questions/74417624/how-does-clang-... is someone asking why the compiler replaced: int a = 0; while (n--) a += (n * n); an O(n) algorithm, with the O(1) equivalent of: a = n * (n-1) / 2 + n
- zimpenfish 3y agoI think your `n * (n-1) / 2 + n` should be `n(n+1)(2n+1)/6` according to the SO article. `n * (n-1) / 2 + n` would be the sum of numbers, not sum of squares.
- eesmith 3y agoThank you for the correction!
- ska 3y ago> Programming used to be very different from what it is now Programming has definitely evolved. This maxim seems to be exactly as applicable then as it is now though, and as misunderstood.
- deleted 3y ago[deleted]
- randomdata 3y agoI don't see how the larger quote adds any additional meaningful context. Once you have identified (measured) the critical 3%, the state is no longer premature. That is already implied in "Premature optimization is the root of all evil". The the maxim is not "Optimization is the root of all evil".
- Narishma 3y ago> The the maxim is not "Optimization is the root of all evil". In my experience, that's exactly how most people understand it.
- bawolff 3y agoI don't see anyone taking this out of context here. The entire quote is less pithy but not different in meaning. "Premature" is literally the first word.
- avg_dev 3y agoHow is this not covered by points 1 (don't put in hacks because of guessing) and 2 (measure)?
- mcphage 3y ago> this quote is frequently taken out of context to argue against optimization in general Maybe it is, but that's not how it's being used in this context.
- deleted 3y ago[deleted]
- MarkMarine 3y agoToo many people take this as dogma and just don’t learn the efficient way to do things. I’ve lost count of the number of FE devs that interview in my company’s DS&A section and tell me bubble sort is the best we can do. I don’t need a derivation off the top of your head, just know a couple and tell me a good choice for the problem and I’m good… same thing here. If people live the “don’t prematurely optimize” to the point that they don’t even know the efficient ways to do things, how will they know where it’s important.
- sdfghswe 3y agoPremature "premature optimization is the root of all evil" is the root of all evil.
- deleted 3y ago[deleted]
- justin66 3y ago> The point is to spend time optimizing where it will have impact. Your whinging would be more appropriate if Measurement was not emphasized, right near the top.