Refactor when the code is about to cost you, not when it smells

Ravi Menon, Developer tooling editor (AI-assisted) · · updated

Refactor the code you are about to touch, once tests cover it, and leave the rest alone. Research does not give you a number for what debt costs: the 2015 study of half a million commits found empirical evidence of consequences but only anecdotal evidence on how, when or why they occur [3].

What the research can and cannot tell you

Technical debt is a qualitative description of the maintenance cost that comes from choosing an expedient solution, and it is generally assessed after a development effort, not measured up front [1]. So no dashboard will hand you a debt figure to act on.

One 2015 study ran automated analysis on half a million source code commits and manually examined 9,164 commits determined to exhibit code smells [3]. It reported that there is empirical evidence for the consequences of technical debt, but only anecdotal evidence as to how, when or why those consequences occur [3]. In other words, the study does not tell you which smells will cost you, or under what conditions.

The sources do say what leaving debt unaddressed can lead to: reduced maintainability, increased development costs and risk to production systems [1]. Those are the costs to weigh against the price of a refactor. Smells themselves are weaker evidence. Whether something counts as a smell is subjective and varies by language, developer and development methodology [3], and smells are usually not bugs; they hint at weaknesses that may slow development or raise the risk of future failures [3]. Metrics intended to assess code quality exist, but developers often do not rely on them when deciding what to refactor, because they doubt the metrics are useful in practice [2].

Treat a smell as a question, not a ticket

Smells such as duplicated code, a god object, a data clump or a long parameter list are usually not bugs and do not stop the program working [3]. They hint at design weaknesses that may slow development or raise future bug risk [3].

Cunningham's original meaning was a suggestion that something may be wrong, not proof that a problem exists [3]. That argues against a rule like "fix every smell a tool reports". Checkstyle, PMD, FindBugs and SonarQube will find plenty [3]; the finding tells you where to look, not what to schedule.

Developers themselves are cautious here: they often do not rely on code metrics when deciding to refactor, doubting their practical usefulness [2].

Questions readers ask

Is there a number for how much technical debt costs?

Not in these sources. Debt is assessed retroactively and described qualitatively [1], and the large commit study found evidence of consequences but not how, when or why they arise [3].

Should I schedule a dedicated refactoring sprint?

The sources do not test that. They do support the smaller habit: refactoring continuously keeps code easier to extend and maintain [2], and a shared-responsibility approach lets the original author prepare code so a later developer does the actual refactor [2].

Does a code smell mean the code is broken?

No. Smells are usually not bugs and the program still works [3]. They are heuristics for when to refactor and which technique to use [3].

*Corrected 2026-11-27: Removed two sentences about how this article was put together; they did not help readers. The study's finding is unchanged.*

Sources

  1. Technical debt - Wikipedia
  2. Code refactoring - Wikipedia
  3. Code smell - Wikipedia

More articles