DEV Community

CBT Tools
CBT Tools

Posted on

Legacy Code Anxiety for Senior Engineers: 6 Cognitive Distortions That Hit When You Touch Old Code

Legacy Code Anxiety for Senior Engineers: 6 Cognitive Distortions That Hit When You Touch Old Code

You're not afraid of the code. You're afraid of what the code represents — and that's a cognitive distortion. Here's how to spot it and break it.


The Legacy Code Trap for Senior Engineers

You've been asked to fix a bug in a 5-year-old module. No tests. No documentation. The original author left the company 3 years ago.

Your heart rate spikes. What if you break something? What if you don't understand it? What if they think you're not smart enough?

Legacy code anxiety isn't about the code — it's about fear of the unknown, fear of breaking something you don't understand, and fear of being exposed as not smart enough. For senior engineers, this anxiety is compounded by the weight of responsibility: you're the expert now, and there's no one to ask.

Key insight: Legacy code anxiety has unique distortions for senior engineers that don't show up in junior anxiety. The "I should rewrite it" urge, the "I'm not smart enough" fear, and the "I'll break the magic" paralysis are senior-specific.


6 Senior-Specific Legacy Code Distortions

1. The "I Should Rewrite It" Urge

The distortion: "This code is a mess. I should rewrite it from scratch. It would be faster."

How it sounds:

  • "I could rewrite this in a weekend. It would be cleaner."
  • "The original author didn't know what they were doing. I'll do it right."
  • "Refactoring is too slow. A rewrite is faster."

The CBT break:

The "rewrite urge" is all-or-nothing thinking disguised as technical judgment. You're assuming the code is a mess because you don't understand it yet — not because it IS a mess. A rewrite introduces NEW bugs, not fixes old ones.

Reframe: "I don't understand this code YET. Rewriting it would introduce NEW bugs. Refactoring is slower but safer. My job is to understand, not to rewrite."

Action: Before declaring a rewrite, spend 2 hours tracing the code. Write down what you learn. 90% of the time, you'll discover: it's not as messy as it looks.


2. The "I'm Not Smart Enough" Fear

The distortion: "I don't understand this code. I'm not smart enough to be a senior engineer."

How it sounds:

  • "The original author was a genius. I'll never understand this."
  • "I've been staring at this for 2 hours. I'm not cut out for this."
  • "If I were smarter, I'd get it faster."

The CBT break:

The "not smart enough" fear is labeling — taking a temporary state (not understanding) and turning it into a permanent identity (not smart). The original author wasn't a genius — they had context you don't have.

Reframe: "I don't understand this code YET. The original author had context I don't have. My job is to build that context — not to be a genius."

Action: Write down what you DO understand. Then write down what you DON'T understand. Ask for context from someone who was there. You'll discover: you're not dumb — you're missing context.


3. The "I'll Break the Magic" Paralysis

The distortion: "This code works, but I don't know why. If I touch it, I'll break it."

How it sounds:

  • "I'm afraid to touch this. It's magic."
  • "If I refactor this, something will break in production."
  • "I'll leave it alone. It works — don't fix what isn't broken."

The CBT break:

The "magic" fear is fortune telling — predicting a negative outcome (breaking production) without evidence. Code that "just works" without tests IS a risk — but avoiding it doesn't fix the risk. It just delays the explosion.

Reframe: "This code is a time bomb. Avoiding it doesn't fix the risk — it just delays the explosion. My job is to defuse the bomb, not to run from it."

Action: Write a test for the behavior you're about to change. If you can't write a test, add logging to understand the behavior. Then change with confidence.


4. The "We'll Fix It Later" Fallacy

The distortion: "We'll fix this later. For now, let's ship the feature."

How it sounds:

  • "We'll refactor this after the deadline."
  • "Let's ship now and fix tech debt later."
  • "We don't have time to refactor. We'll do it in the next sprint."

The CBT break:

The "fix it later" fallacy is emotional reasoning — justifying avoidance with a feeling (we don't have time) rather than a fact. "Later" never comes. The tech debt accumulates, and the codebase becomes legacy code while you're still working on it.

Reframe: "Later is a lie. If we don't fix it NOW, we never will. Tech debt accumulates while we're working. The codebase is becoming legacy code while we're still building it."

Action: For every feature, ask: "What tech debt are we accumulating?" Write it down. Schedule 20% of each sprint for tech debt reduction. If you can't schedule it, the feature isn't ready to ship.


5. The "Original Author Mind Reading" Trap

The distortion: "The original author was an idiot. They didn't know what they were doing."

How it sounds:

  • "Why would they write this? They were incompetent."
  • "This is a terrible design. They didn't think about X."
  • "I should have been consulted. This is a mess."

The CBT break:

The "original author mind reading" trap is mind reading — assuming you know why the author wrote the code without context. The author wasn't an idiot — they had constraints you don't have: deadlines, requirements, context.

Reframe: "The original author had constraints I don't have. Deadlines, requirements, context. This code made sense THEN. My job is to understand WHY, not to judge."

Action: Write down 3 reasons the code might have been written this way. Ask for context from someone who was there. You'll discover: the author wasn't an idiot — they were working with constraints.


6. The "It Works, Don't Touch" Trap

The distortion: "This code works. I shouldn't touch it. If it ain't broke, don't fix it."

How it sounds:

  • "I'm not touching that. It works."
  • "We'll leave it alone. It's not broken."
  • "Refactoring is risky. Let's not introduce bugs."

The CBT break:

The "don't touch" trap is avoidance — avoiding discomfort (fear of breaking) rather than addressing the risk. Code without tests IS broken — you just haven't discovered how yet. Avoiding it doesn't fix the risk.

Reframe: "Code without tests IS broken — you just haven't discovered how yet. Avoiding it doesn't fix the risk. My job is to address the risk, not to avoid it."

Action: Write a test for the behavior. If you can't, add logging. Then refactor with confidence. You'll discover: the code is more robust than you thought.


The Legacy Code Refactoring Protocol for Senior Engineers

Here's a 4-week action plan based on CBT principles:

Week 1: Identify Your Distortions

  • Track your thoughts for 3 days before touching legacy code. Which distortions appear most?
  • Use the Distortion Detector to spot them in real-time.
  • Write down: "My top 3 distortions are X, Y, Z."

Week 2: Challenge the Distortions

  • For each distortion, write down the evidence FOR and AGAINST.
  • Create a reframe for each distortion.
  • Example: "I don't understand this code YET → The author had context I don't have."

Week 3: Take Targeted Action

  • For each distortion, take one small action.
  • "I should rewrite it" → Spend 2 hours tracing the code.
  • "I'm not smart enough" → Write down what you DO understand.
  • "I'll break the magic" → Write a test for the behavior.

Week 4: Build Refactoring Habits

  • Write tests before refactoring.
  • Add logging to understand behavior.
  • Refactor in small, safe increments.
  • Ask for context from someone who was there.

The Key Insight

Legacy code anxiety is not a personal failing — it's a systematic thinking pattern that can be identified, challenged, and broken.

The senior engineers who refactor fastest aren't the ones who are smartest. They're the ones who spot the distortions early and apply CBT breaks.

You're not afraid of the code. You're afraid of what the code represents. Address the fear, and the code becomes manageable.


If this resonated, follow me for more CBT × developer content. I build free interactive mental health tools at CBT Toolkit — no signup, no privacy issues, just tools that work.

Related articles:

Top comments (0)