DEV Community

CBT Tools
CBT Tools

Posted on

5 Cognitive Distortions That Hit When Touching Legacy Code (And How to Break Them)

Legacy code isn't the problem. The cognitive distortions it triggers are.


The Legacy Code Trap

You've been told not to touch it. The comment says "don't refactor this, it's fragile." The tests don't exist. The original author left three years ago. And now you need to fix a bug in it.

Legacy code anxiety is the paralysis that hits when you're staring at 2000 lines of undocumented, untested, "it works so don't touch it" code. It's not about skill — it's about catastrophic thinking about breaking something you don't understand.

The irony: The more you avoid touching it, the scarier it becomes. And the scarier it becomes, the more you avoid it.


5 Developer-Specific Legacy Code Distortions

1. The "Don't Touch" Fallacy

Typical thought: "The comment says don't touch it. If I touch it, I'll break something. I should leave it alone and find a workaround."

CBT Reframe: "'Don't touch' is a warning, not a prophecy. Tests + gradual changes = safe exploration. The workaround is often riskier than the fix."

Technique: Characterization tests before refactoring.


2. Catastrophic Breakage

Typical thought: "If I change this one line, the whole system will collapse. I don't understand all the dependencies, so I can't know what will break."

CBT Reframe: "Fear of breaking is fear of understanding. Tests are my safety net. Start with characterization tests, then refactor."

Technique: Test-first refactoring.


3. The "I'm Not Smart Enough" Story

Typical thought: "The original author understood this. I'm not smart enough to refactor it. I'll just make it worse."

CBT Reframe: "The original author had context I don't have. Understanding is a process, not a fixed state. I don't need to understand everything — just enough to make the change safely."

Technique: Incremental understanding.


4. The "It Works" Trap

Typical thought: "It works in production. If I touch it, I might introduce bugs. The risk isn't worth it."

CBT Reframe: "'It works' ≠ 'it's maintainable'. Technical debt is a risk too. The question isn't 'will I break it?' but 'how can I make it safer to change?'"

Technique: Risk-benefit analysis.


5. The "I Should Rewrite It" Urge

Typical thought: "This is a mess. I should just rewrite it from scratch. That would be cleaner than refactoring this spaghetti."

CBT Reframe: "Rewriting from scratch is often riskier than refactoring. The existing code has years of bug fixes. Start with small, safe refractions. Big rewrites are a last resort."

Technique: Boy Scout Rule (leave it cleaner than you found it).


The 5-Minute Legacy Code Reframe

When you freeze staring at that "don't touch" comment:

  1. Notice: "I'm feeling frozen about this legacy module."
  2. Identify: "This is the 'Don't Touch' Fallacy + Catastrophic Breakage."
  3. Evidence: "What evidence do I have that I'll break it? Have I written characterization tests? Have I read the code carefully?"
  4. Reframe: "Tests are my safety net. Start with one small characterization test, then refactor."
  5. Action: "One small step: write ONE characterization test for the current behavior."

Free CBT Tools

I built 855 free CBT tools for developers — pure JavaScript, no signup, no backend:

Tool Purpose
CBT for Legacy Code Anxiety 6 distortions + interactive thought record
Thought Record Tool Capture and reframe distorted thoughts
Imposter Syndrome Tool Track evidence against "I'm a fraud"

Summary

Legacy code isn't the problem. Cognitive distortions are.

5 distortions to watch for:

  1. "Don't Touch" Fallacy — Tests are your safety net
  2. Catastrophic Breakage — Characterization tests first
  3. "I'm Not Smart Enough" — Understanding is a process
  4. "It Works" Trap — Technical debt is risk too
  5. "I Should Rewrite It" — Small refractions first

Next time you freeze at legacy code: Write ONE characterization test. That's the reframe.


Built with vanilla JS. No tracking, no signup, no backend. Data stays in your browser.

855 free CBT tools — 2026


Free CBT Thought Record Template

I built a CBT Thought Record Notion template with the 7-column method, 10 cognitive distortions reference, worked example, and daily practice guide.

Get it here → Gumroad - CBT Thought Record ($7)

Or duplicate the Notion template directly and customize it.

Top comments (0)