Premature optimization is the root of all evil
c2.com
c2.com
People need to learn their history before throwing out such maxims.
Efficient code should always be on your mind, but actual optimisation probably ought to be done with the aid of a profiler rather than a hunch a 'clever' way of doing something.
Premature optimisation is optimisation without knowing what needs to be optimised.
We live in a an age where computers are so fast it's considered acceptable to be an engineer and just blurb out code and show people that "shit just works".
That quote is indeed very misleading, because at the time, CPU were still getting faster frequencies, so optimizing problems were solving themselves.
Today we face a problem where the faster algorithms are the one we need, because multithreading is hard, and also because there is no real tech to do clustering out of the box.
I'll always smirk when I look at this quote, and look at spidermonkey, v8, chrome, and carmack's
Since the same guys are doing the crunch phase optimizations, their prejudices have a survival bias which carries a lot of apparent "battle hardened" weight
When I first started programming professionally and read this quote, I thought it didn't really apply to me. I do a lot of low-traffic webapps and never really felt like I did much trade-off with premature optimization. It certainly sounded strong to say that pre-mature optimization was the root of all evil. Hell, I messed up so many other things that I would have picked any one of them and thought it to be more of a problem. But I respected the person saying it, so I kept it in the back of my mind.
Then I had an epiphany. Pre-mature optimization isn't just about performance, and it doesn't even have to be about only programming. In your business, are you focusing on automating something that will only save a miniscule amount of time? Are you building a feature that will rarely ever be used? Sounds like pre-mature optimization to me. And the problem is not that the end-product won't be better; the problem is the opportunity cost. You're trading off a whole host of other things that could be worked on instead.
Pre-mature optimization for me comes down to reassessing where I am at every stage of building a project and asking myself: am I focused on the right thing? Because if not, I'm wasting my time.
The point is that in many cases, you should optimize for readability and simplicity first, and optimize for performance only if it's likely to become an issue. If you optimize for performance first, you may well have massively increased your cost of development for incremental performance gains that you could have got by throwing a bit more hardware at the problem.