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 the highest cost per instance 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 for one instance of each smell on a team of 8, using the mid inputs of our cost model at $180K fully-loaded cost per engineer. Fix hours are our own estimates. Your ranking will differ with instance counts: use the smell profile calculator.
| # | Smell | Severity | Model cost/yr | Fix (hrs, est.) | Priority Score |
|---|---|---|---|---|---|
| 1 | Dead CodeQuick Win | Low | $4K | 0.25 | 15,784 |
| 2 | Comments (as Smell)Quick Win | Low | $4K | 0.5 | 7,892 |
| 3 | Duplicate Code | High | $15K | 3 | 5,077 |
| 4 | Feature Envy | High | $15K | 3 | 5,077 |
| 5 | Primitive Obsession | Medium | $8K | 2 | 4,033 |
| 6 | Long Parameter List | Medium | $8K | 2 | 4,033 |
| 7 | Message Chains | Medium | $8K | 2 | 4,033 |
| 8 | Lazy ClassQuick Win | Low | $4K | 1 | 3,946 |
| 9 | Speculative GeneralityQuick Win | Low | $4K | 1 | 3,946 |
| 10 | Long Method | High | $15K | 4 | 3,808 |
| 11 | Inappropriate Intimacy | High | $22K | 6 | 3,692 |
| 12 | God Class | Critical | $39K | 12 | 3,260 |
| 13 | Data Clumps | Medium | $8K | 3 | 2,688 |
| 14 | Alt Classes/Diff Interfaces | Medium | $8K | 3 | 2,688 |
| 15 | Temporary Field | Medium | $8K | 4 | 2,016 |
| 16 | Refused Bequest | Medium | $8K | 4 | 2,016 |
| 17 | Data Class | Low | $4K | 2 | 1,973 |
| 18 | Middle Man | Low | $4K | 2 | 1,973 |
| 19 | Shotgun Surgery | High | $15K | 8 | 1,904 |
| 20 | Divergent Change | High | $15K | 10 | 1,523 |
| 21 | Switch Statements | Medium | $8K | 6 | 1,344 |
| 22 | Parallel Inheritance | High | $15K | 12 | 1,269 |
Priority Score = model cost per instance a year / estimated 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.