Code Smell 20 — Premature Optimization
Planning ahead of time needs a crystal ball no developer has.
Planning ahead of time needs a crystal ball no developer has.

Problems
Coupling
Testability
Readability
Solutions
Create great models and bijections first.
Create a conclusive benchmark once the model is working.
Programmers waste enormous amounts of time worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. Donald Knuth
Use Test Driven Development technique. It always favors the simplest solution.
Examples
Weird data structures
Caches
Singletons
Sample Code
Wrong
Right
Detection
This is a design smell so it can not be detected by mechanical tools (yet).
Tags
Premature Optimization
Antipattern
Conclusion
Defer performance decisions until functional models are mature enough.
Donald Knuth created/compiled the best/fastest algorithms and data structures. With great wisdom he warned us of abuse. Why do we think we are smarter than him?
Relations
Code Smell 06 — Too Clever Programmer
Code difficult to read. Tricky with names without semantic. Sometimes using language’s accidental complexity.medium.com
More info
Singleton: The Root of all Evil
Allowed global variables and supposed memory savingscodeburst.io
Premature optimization is the root of all evil.
Donald Knuth
Software Engineering Great Quotes
Sometimes a short thought can bring amazing ideas.medium.com
This article is part of the CodeSmell Series.
How to Find the Stinky parts of your Code
The code smells bad. Let’s see how to change the aromas.medium.com

