Use when analyzing cognitive load, code complexity, onboarding difficulty, readability concerns, maintainability issues, or applying Ousterhout principles for deep modules, reducing complexity, and...
Complexity comes from dependencies and obscurity. Reduce it by making modules deeper — simple interfaces hiding significant implementation. Measure depth as implementation power divided by interface complexity.
| Level | Smell | Fix |
|---|---|---|
| L0 | Generic names | Rename to describe domain concepts |
| L1 | >4 params, >3 nesting levels, >40 line functions | Group into structs, extract named functions |
| L2 | Callers duplicate checks, must call in order | Pull complexity downward, deepen the interface |
| L3 | Branching grows with each new type | Protocols to eliminate special cases |
| L4 | Can't find things, features touch 8 files | Organize by domain (Phoenix contexts) |
| L5 | Accumulated tactical debt | Strategic refactoring — one protocol/module per PR |
Code is confusing. Why?
Names are unclear → Level 0 (rename)
Too much to track at once → Level 1 (reduce working memory)
Module is hard to use → Level 2 (deepen the interface)
Branching keeps growing → Level 3 (eliminate special cases)
Can't find things → Level 4 (architectural clarity)
Accumulated debt → Level 5 (strategic refactoring)
DeepCache.put(key, val) beats ShallowCache.put(key, val, ttl, serializer, compression)with internallyprocess, handle, data — forces reading implementation to understand intentRead the file that matches your current problem:
escalation-ladder.md — When: Need thresholds and code examples for each complexity level. Full Complexity Reduction Ladder (L0-L5 with code examples, thresholds)ousterhout-principles.md — When: Evaluating module depth or interface design. Deep modules, information hiding, strategic programming, SRK interface designreferences/metrics.md — When: Measuring cognitive complexity numerically. Cognitive complexity metricsreferences/patterns.md — When: Looking for specific refactoring techniques. Refactoring patterns catalogreferences/onboarding.md — When: Assessing how hard code is for new developers. Onboarding difficulty assessment/cognitive-audit — Full complexity analysis with onboarding difficulty assessment/review [file] — Review code including complexity evaluation