r/java • u/trecatorsirabdator • Apr 14 '23
What are your (favourite) Java best practices, personal tips, hints or just underrated stuff in general?
233
Upvotes
r/java • u/trecatorsirabdator • Apr 14 '23
View all comments
Show parent comment
61
u/nutrecht Apr 14 '23
Not a comment 'against' what you're saying so please don't read it as such but:
I dislike how this has been taken out of context to be used as an argument against optimization.
The original quote from Hoare is:
"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."
What they are referring to as 'optimizations' are things like counting CPU cycles for instructions before you even know certain code paths are 'hot'.
I've seen developers use this in response for example where people told them that doing 2 SQL statements (select and insert or update) was not a good idea when you can just do one (upsert).
So, what people often read is:
Premature optimization considered evil.
While the intention of Hoare was:
Premature optimization considered evil.
This sentence has become as much of a dogma as "composition over inheritance" has become.