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

Priority Score = (Annual Cost per Instance x Instance Count) / Fix Effort (hours)
Highest score = fix first. Score represents dollars saved per hour of refactoring invested.

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.

Dead CodeQuick Win

Highest ROI: delete and trust version control. Zero risk. 5-15 minutes per block. Immediate reduction in reading burden.

Fix: 15 minScore: 10,000
Lazy ClassQuick Win

Quick win: inline the class and remove one navigation hop. 30-60 minutes. Low risk.

Fix: 1 hrsScore: 3,000

Quick win: collapse unnecessary abstractions. If 'we might need this later' has been true for 6+ months, delete it.

Fix: 1 hrsScore: 3,500

Extract methods to replace 'what' comments. 15-30 minutes per block. Reduces stale comment risk.

Fix: 30 minScore: 3,000

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.

#SmellSeverityAvg Cost/yrFix (hrs)Priority Score
1Dead CodeQuick WinLow$2,5000.2510,000
2Duplicate CodeHigh$15,00035,000
3Primitive ObsessionMedium$9,00024,500
4Long MethodHigh$16,00044,000
5Feature EnvyHigh$12,00034,000
6Speculative GeneralityQuick WinLow$3,50013,500
7Long Parameter ListMedium$7,00023,500
8Lazy ClassQuick WinLow$3,00013,000
9Comments (as Smell)Quick WinLow$1,5000.53,000
10Message ChainsMedium$6,00023,000
11God ClassCritical$30,000122,500
12Shotgun SurgeryHigh$20,00082,500
13Data ClumpsMedium$7,50032,500
14Inappropriate IntimacyHigh$14,00062,333
15Alt Classes/Diff InterfacesMedium$7,00032,333
16Refused BequestMedium$8,00042,000
17Data ClassLow$4,00022,000
18Divergent ChangeHigh$16,000101,600
19Middle ManLow$3,00021,500
20Temporary FieldMedium$5,50041,375
21Parallel InheritanceHigh$14,000121,167
22Switch StatementsMedium$6,00061,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.