Which Code Smells to Fix First: A Cost-Weighted Prioritisation Framework
Not all smells deserve equal attention. This framework ranks smells by the ratio of annual cost to fix effort, giving you a data-driven order for remediation that maximises ROI per hour invested.
The Prioritisation Formula
The formula favours smells that are cheap to fix relative to their cost impact. Dead Code tops the ranking because removing it takes minutes but eliminates ongoing reading burden. God Classes rank lower despite their massive absolute cost because fixing them requires significant effort.
Quick Wins: Start Here
These smells are cheap to fix, low risk, and build momentum for larger refactoring efforts. Do these first to demonstrate value before tackling God Classes.
Highest ROI: delete and trust version control. Zero risk. 5-15 minutes per block. Immediate reduction in reading burden.
Quick win: inline the class and remove one navigation hop. 30-60 minutes. Low risk.
Quick win: collapse unnecessary abstractions. If 'we might need this later' has been true for 6+ months, delete it.
Extract methods to replace 'what' comments. 15-30 minutes per block. Reduces stale comment risk.
Default Priority Ranking
Pre-calculated ranking for a "typical" codebase with medium size and 5 developers. Your specific ranking may differ based on instance counts. Use the homepage calculator for personalised data.
| # | Smell | Severity | Avg Cost/yr | Fix (hrs) | Priority Score |
|---|---|---|---|---|---|
| 1 | Dead CodeQuick Win | Low | $2,500 | 0.25 | 10,000 |
| 2 | Duplicate Code | High | $15,000 | 3 | 5,000 |
| 3 | Primitive Obsession | Medium | $9,000 | 2 | 4,500 |
| 4 | Long Method | High | $16,000 | 4 | 4,000 |
| 5 | Feature Envy | High | $12,000 | 3 | 4,000 |
| 6 | Speculative GeneralityQuick Win | Low | $3,500 | 1 | 3,500 |
| 7 | Long Parameter List | Medium | $7,000 | 2 | 3,500 |
| 8 | Lazy ClassQuick Win | Low | $3,000 | 1 | 3,000 |
| 9 | Comments (as Smell)Quick Win | Low | $1,500 | 0.5 | 3,000 |
| 10 | Message Chains | Medium | $6,000 | 2 | 3,000 |
| 11 | God Class | Critical | $30,000 | 12 | 2,500 |
| 12 | Shotgun Surgery | High | $20,000 | 8 | 2,500 |
| 13 | Data Clumps | Medium | $7,500 | 3 | 2,500 |
| 14 | Inappropriate Intimacy | High | $14,000 | 6 | 2,333 |
| 15 | Alt Classes/Diff Interfaces | Medium | $7,000 | 3 | 2,333 |
| 16 | Refused Bequest | Medium | $8,000 | 4 | 2,000 |
| 17 | Data Class | Low | $4,000 | 2 | 2,000 |
| 18 | Divergent Change | High | $16,000 | 10 | 1,600 |
| 19 | Middle Man | Low | $3,000 | 2 | 1,500 |
| 20 | Temporary Field | Medium | $5,500 | 4 | 1,375 |
| 21 | Parallel Inheritance | High | $14,000 | 12 | 1,167 |
| 22 | Switch Statements | Medium | $6,000 | 6 | 1,000 |
Priority Score = Average Annual Cost / Average Fix Hours. Higher score = fix first.
When NOT to Refactor
An honest prioritisation framework must include when refactoring is a waste of time. These are the situations where the cost of refactoring exceeds the benefit:
Code scheduled for replacement
If a module will be replaced within 3-6 months, refactoring it wastes effort on code that will be deleted. Exception: if the smelly code is causing production incidents before the replacement ships, tactical fixes (not structural refactoring) are warranted.
Isolated, stable modules
Code that works correctly, is rarely changed, and is well-tested does not benefit from refactoring. A God Class in a module that has not been modified in 12 months costs almost nothing in practice because nobody is reading, changing, or onboarding onto it.
Smells in test code
Test code has different cost dynamics. Long test methods that are descriptive and readable are fine. Duplicate setup code in tests is acceptable when it makes each test self-contained. Focus refactoring effort on production code first.
No test coverage for the refactoring target
Refactoring without tests is not refactoring; it is rewriting with hope. If the target code has no automated tests, the first step is to add characterisation tests before any structural changes. This is a cost you must include in the effort estimate.
Ready to build a business case? Calculate your costs and estimate refactoring ROI.