Speculative Generality — Code Smells Catalog Skip to content

Speculative Generality

Dispensables Unnecessary Complexity AntipatternCode SmellDesign Smell Between Class

An abstract base class for a hierarchy that never grew. Three extra parameters for a feature you were sure someone would request. Abstractions built for a future that never arrived, cluttering the...

2 min read 1 source

Overview

Developers are humans, and humans are bad guessers [1]. Developers tend to create additional features in preparation for the future, guessing they will be useful, but that time never came. This problem lies within the human psychological nature and, contrary to their best intentions, it just clutters the code.

Causation

Psychologically, humans tend to anticipate scenarios and prepare for them.

Problems

You Ain't Gonna Need It Principle Violation

The whole system is trying or expecting to do more than it is supposed to.

🧩
Increased Complexity

Each additional method, class, or module increases the required time and effort to understand it as a whole.

Example

Context: Medieval Fighting Game
1class Animal:
2    health: int
3
4class Human(Animal):
5    name: str
6    attack: int
7    defense: int
8
9class Swordsman(Human):
10    ...
11
12class Archer(Human):
13    ...
14
15class Pikeman(Human):
16    ...
PYTHON

Refactoring

  • Collapse Hierarchy
  • Inline Function
  • Inline Class
  • Rename Method

Sources

Browse All 56 Smells