Cognitive load is how much a developer needs to think in order to complete a task.
🧠: fresh working memory, zero cognitive load
🧠++: two facts in our working memory, cognitive load increased
🤯: working memory overflow, more than 4 facts
Common reasons for cognitive overload
- Complex conditionals - introduce meaningfully named intermediate variables
- Nested
ifs - prefer early returns - Inheritance nightmare - prefer composition over inheritance
- Too many small methods, classes or modules
- Shallow modules
- Shallow micro-services
- Abusing the DRY principle