FYI there is this crap above because the forum won’t stop inserting this and jacking up my post, this is the best I can do.
It seems like you’re making your point invalid with your own quotes. Also, your mindless judgmental insult of professors (both my parents are professors, by the way) further dilutes any valid point you may have had in your statement.
Nobody has ever told me “optimization is the root of all evil,” in school or otherwise. I have always heard “premature optimization is the root of all evil,” which, lo and behold, is exactly what Knuth said. Guess what I was often reading in school and taught had good philosophies to think about? Knuth. And who put me down that path? Professors.
Reading other peoples’ follow-up posts, I see they are all providing examples of exactly the same point. Don’t optimize prematurely. The proper development path is to write as good code as you can without stressing over performance, instead focus on good design, readability, and modularity. Then when you find something is too slow you find out why and fix it. End of story. Se get off your high horse because nobody is going to raise their hand saying that optimization in general is a bad thing.
Gotos, maybe, but I find that’s personal opinion, because there are a lot of ways to do the same thing you’d use gotos for.
/////////////////////////////////////
Now my true story:
I worked on an iPhone game that was very much in the prototype stage, and had been in development for a couple months. We were playing around with different ways of doing things and making it fun. Because we were short people, we hired another engineer. To get familiar with the code, he was supposed to write a level editor. Instead, he went through the entire codebase (tens of thousands of lines long) and did these optimizations:
Change all:
for (int i = 0; i < arrayList.length; i++)
to:
for (int i = arrayList.length-1; i > -1; i--)
Why? Because we avoid calling .length more than once and therefore it’s faster. Let’s forget about any potential compiler optimizations there are and assume he’s right. The most we’d be looping through is maybe 100 things. So, he saved maybe a fraction of a nanosecond every once in a while.
Change all:
if (i >= 0 || x >= array.length || y >= 0 || z <= n)
to:
if (i > -1 || x > array.length-1 || y > -1 || z < n+1)
Why? Also apparently faster. Any LTE or GTE checks he decided required two checks (> and ==) and therefore was slower. This sounded totally insane to me, but I’ve never prided myself at knowing exactly what goes on under the hood so I let him have his declaration for the moment. A few minutes of Googling later and I had several links telling him he was very wrong. His response was “okay” but behind his eyes it seemed like he didn’t trust the links I gave him. Also, his changes are insanely difficult to read.
Change all:
float f = obj.thingy.x + obj.thingy.y;
to:
Thingy thingy = obj.thingy;
float f = thingy.x + thingy.y;
Yes, this one is actually fractionally faster. Although with compilers these days I’d question that too. And once again you’re sacrificing readability by having massive line bloat.
I know I’ve said some pretty stupid assumptions or misunderstandings on these forums (yes nobody needs to point them out to me), so I’m not saying I’m spotless. But I would never go into an active codebase and start rewriting everything completely pointlessly instead of doing my job.
Did I mention I was the lead on that project? He didn’t work there much longer.