Item 37: Optimize judiciously
There are three aphorisms concerning otptimization that everyone should know. They are perhaps beginning to suffer from overexposure, but in a case you aren't yet familiar with them, here they are:
- More computing sins are commited in the name of efficiency (without necessarly achieving it) that for any other single reason - including blind stupidity.
- Wiliam A. Wulf (A case Agains the GOTO, Proceedings of the 25th ACM NAtional Conference 2 (1972))
- We
should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.
- Donald E. Knuth (Structured Programming with go to Statements, Computing Survey 6 (1974)).
- We follow two rules in the matter of optimization :
Rule 1. Don't do it.
Rule 2 (for experts only). Don't do it yet - that is, not until you have a perfectly clear and unoptimized solution.
- M. A. Jackson (Principles of Program Design, Academic Press (1975))
All of there aphorisms predate the Java programming language by two decades. They tell a deep truth about optimization: it's easy to do more harm than good, especially if you optimize prematurely. In the process, you may produce software that is neither fast nor correct an cannot easily be fixed.
Don't sacrifice sound architectural principles for performance.
Strive to write good programs rather than fast ones.
( ... )
Partager