Speculative Generality Smell
What you'll learn: You'll learn to identify when code has been over-engineered with unnecessary abstractions built for imagined future needs that may never materialize.
What Is Speculative Generality?
Speculative Generality occurs when developers add hooks, parameters, abstract classes, or complex frameworks anticipating future requirements that haven't actually been requested or proven necessary. It's the "what if we need this someday?" mentality that clutters your codebase with unused flexibility.
Think of it like building a house with 20 bedrooms because "maybe someday we'll need guest rooms for everyone we might ever meet." You're paying construction costs (complexity, maintenance burden) for rooms that will likely sit empty forever.
Common Signs
- Abstract classes or interfaces with only one concrete implementation
- Parameters passed through multiple function calls but never actually used
- Elaborate plugin architectures when you only have one plugin
- Conditional logic branches that are never executed
- Overly generic naming like
AbstractBaseHandlerFactoryImpl
Why It's Harmful
Every abstraction adds cognitive load. Future developers must understand not just what the code does, but what it could theoretically do. This makes debugging harder, increases test surface area, and slows down simple changes because you're navigating through unnecessary layers.
The irony? When actual new requirements arrive, they rarely match your speculation, making those abstractions useless or even obstructive.
The Fix
Remove unused abstractions. Inline single implementations. Delete unused parameters. Follow YAGNI (You Aren't Gonna Need It) — add generality only when you have concrete, current evidence that it's needed. Refactoring patterns like Inline Method and Remove Parameter help eliminate speculative code.
Key Takeaway: Speculative Generality sacrifices today's simplicity for tomorrow's hypothetical flexibility — resist the urge to over-engineer and design for actual requirements, not imagined ones.