Home Knowledge Base 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?

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.

# 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:

speculative generalitycode smellyagni

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.