News for hackers. Stuff that matters.
Re:Optimizations on Linear Search (2016) by dahart on Saturday October 03, 2020 @11:23AM (#24672614)
> Donald Knuth famously wrote that premature optimization is the root of all evil.

It’s funny how often Knuth’s actual point is left out of the re-telling of this quote. The actual point he was making was “we should not pass up our opportunities [to optimize] in that critical 3%.“ He wasn’t suggesting the avoidance of optimization, he was suggesting the avoidance of premature optimization.

Re:Optimizations on Linear Search (2016) by staticassertion on Saturday October 03, 2020 @12:41PM (#24673130)
It's also Knuth quoting Tony Hoare, a man who I highly recommend everyone familiarize themselves with, he's a wonderful speaker and is extremely intelligent.

The context of the quote from both Hoare and Knuth is critical, and is always left out.

"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."

ie: 3% of the time you should absolutely care about 'small' efficiencies. Given that most programs spend almost all of their time in a few places, this is hardly surprising, and 3% is actually a fairly sizable amount of code to optimize to the degree which the paper is discussing (most people are rarely dropping to tools like goto for performance).

And, from the same paper (Structured Programming with goto Statements):

"The conventional wisdom shared by many of today's software engineers calls for ignoring efficiency in the small; but I believe this is simply an overreaction to the abuses they see being practiced by pennywise-and-pound-foolish programmers, who can't debug or maintain their "optimized" programs. In established engineering disciplines a 12 % improvement, easily obtained, is never considered marginal; and I believe the same viewpoint should prevail in software engineering. Of course I wouldn’t bother making such optimizations on a one-shot job, but when it’s a question of preparing quality programs, I don’t want to restrict myself to tools that deny me such efficiencies."

In other words, we should not write slower code when we can help it. Small efficiencies are well worth attaining in the general case, and the fears of writing 'unreadable' code because it's fast are mostly unfounded.

I believe this has never been truer. It's easier than ever to create highly tuned code that's hidden behind a 0 cost abstraction, and it's well worth it to tune that code for simple and obvious wins - we should never strive for inefficiency, as so many seem to advocate.

Re:Optimizations on Linear Search (2016) by voxl on Saturday October 03, 2020 @11:44AM (#24672754)
The word "premature" is inside your quote.
Re:Optimizations on Linear Search (2016) by dahart on Saturday October 03, 2020 @02:08PM (#24673671)
Right- exactly! If you read the article, it ignored the word premature, and used the quote as a narrative suggestion that people should/would avoid any optimization based on this (incomplete) quote, and based on optimizing taking effort. It was using Knuth as a counter-point, pretending that he was saying not to optimize, and then countering with reasons to consider optimizing anyway.
Re:Optimizations on Linear Search (2016) by gameswithgo on Saturday October 03, 2020 @12:23PM (#24673010)
What gets me about the way people use this quote, is that it is tautological. "premature optimization is bad". Yes, it must be or it would not be premature. But when a kid or new programmer posts on the internet about what is faster, or how to make a thing faster, why do we tell them this? (Most programming communities, it is inevitable that they will be told this). How do the commenters know whether the optimization is premature? Why are they worried about it, when the person is just learning/curious?

Let them get good!

Re:Optimizations on Linear Search (2016) by a1369209993 on Saturday October 03, 2020 @06:32PM (#24675171)
> How do the commenters know whether the optimization is premature?

> when the person is just learning/curious

Not that the code being bad matters in such a case, but if something is just for learning/curiousity, then it is by definition not critically important. Sometimes trying to optimize it is the terminal goal, but it's basically never a relevant instrumental goal.

Re:Optimizations on Linear Search (2016) by gameswithgo on Tuesday October 06, 2020 @10:14AM (#24697827)
A lot of software would be better if more programmers had built up some intuition about performance issues by being encouraged, rather than discouraged, when learning. A lot of kids coming out of college have absolutely no exposure to anything low level, or with regard to constant factor performance improvements.