Member-only story
They Accused Me of Prematurely Optimizing the Code. Wrong!
“Premature optimization is the root of all evil.” If you’re into programming, most probably you have heard the famous Donald Knuth’s maxim numerous times.
I have been thrown with this quote at my face at least a couple of times already, during the Code Review process. I was accused of “premature optimization,” just because I opted for:
- a smaller database index on a column to use less RAM,
- to refactor an If-Statement condition in the order from the lightest to the heaviest to reduce CPU usage and database calls,
- to move computation parts of the code above database call statements to avoid unnecessary database look-ups and return early.
So what is this “premature optimization” exactly? Wikipedia says, that it is:
the act of wasting resources on optimizing source code that does not represent a significant bottleneck.
It seems that by wasting some time (resource) on making a database index smaller and more efficient I did prematurely optimize. After all, some database index wasn’t a “significant” bottleneck of the application.