speculative generality
**Speculative Generality** is a code smell where abstractions, interfaces, or framework-like structures are created for anticipated future needs that never materialize.
## What Is Speculative Generality?
- **Symptom**: Unused abstract classes, empty interfaces, over-parameterization
- **Cause**: Premature optimization or "what if" thinking
- **Effect**: Increased complexity without current benefit
- **Pattern**: YAGNI violation (You Aren't Gonna Need It)
## Why It's a Code Smell
Over-engineered code is harder to understand, test, and maintain. Complexity added "just in case" often becomes technical debt.
```python
# Speculative Generality Example:
# Over-engineered (speculative):
class AbstractDataSourceFactory:
def create_data_source(self, source_type, config): ...
class MySQLDataSourceFactory(AbstractDataSourceFactory): ...
class PostgresDataSourceFactory(AbstractDataSourceFactory): ...
class MongoDataSourceFactory(AbstractDataSourceFactory): ...
# But application only ever uses MySQL...
# Simpler (YAGNI):
class MySQLConnection:
def connect(self, config): ...
# Add abstraction WHEN you actually need multiple DBs
```
**AI Detection of Speculative Generality**:
- Identify abstract classes with single implementations
- Find interfaces with only one implementor
- Detect parameters that are never varied
- Flag unused framework hooks