I had a computer science exam some ~20 years ago where we were writing (like, with pencil and paper!) C code. I had been programming in C since middle school while most of the class was learning C for the first time.
I wrote a very sexy copy loop with pointer arithmetic and a comment to the side explaining why, and pointing to a particular pre-increment in the copy as an optimization.
The TA took points off and wrote that micro optimizations are useless and, verbatim "premature optimization is the root of all evil."
I know exactly which TA wrote it, and he was, and I'm sure still is, an effeminate, arrogant, mincing prick. He just did not understand the code. Luckily I appealed to the professor and he reversed it. Yes, I'm still salty about this.
Writing efficient code isn't premature optimization. "Optimization", in the turn of phrase's context specifically, is supposed to mean corner-cutting and hacky workarounds to save a step or two.
Writing good code in the first place REMOVES the need for optimization.
Writing good code in the first place REMOVES the need for optimization.
No, those are different. Look up the famous Quake 3 root optimisation, technically it's immensely faster, but not considered good code, because it's full of "magic numbers" and incredibly hard to understand while the code nor the comments don't provide any info on what's it's doing at all. It generally take a 15mn video to understand those 3 last lines.
I had a computer science exam some ~20 years ago where we were writing (like, with pencil and paper!) C code. I had been programming in C since middle school while most of the class was learning C for the first time.
I wrote a very sexy copy loop with pointer arithmetic and a comment to the side explaining why, and pointing to a particular pre-increment in the copy as an optimization.
The TA took points off and wrote that micro optimizations are useless and, verbatim "premature optimization is the root of all evil."
I know exactly which TA wrote it, and he was, and I'm sure still is, an effeminate, arrogant, mincing prick. He just did not understand the code. Luckily I appealed to the professor and he reversed it. Yes, I'm still salty about this.
The prick works at Facebook today.
Writing efficient code isn't premature optimization. "Optimization", in the turn of phrase's context specifically, is supposed to mean corner-cutting and hacky workarounds to save a step or two.
Writing good code in the first place REMOVES the need for optimization.
No, those are different. Look up the famous Quake 3 root optimisation, technically it's immensely faster, but not considered good code, because it's full of "magic numbers" and incredibly hard to understand while the code nor the comments don't provide any info on what's it's doing at all. It generally take a 15mn video to understand those 3 last lines.
I watched a video about that a couple of years ago. Great stuff, highly recommended.