The "If It Isn't Broken, Don't Fix It" Mentality
Every team has met the phrase. Someone proposes cleaning up a module, and a senior voice says, "If it isn't broken, don't fix it." There is wisdom in that sentence and there is danger in it. Knowing which is which separates teams that keep improving from teams that slowly fossilise.
Where the saying is right
Changing working code carries risk, and the saying protects against real mistakes:
- Cosmetic rewrites. Renaming everything because you prefer a different style rarely helps users.
- Chasing fashion. Swapping a stable library for a trendy one with no concrete benefit is churn.
- Untested changes. Modifying code nobody understands, with no safety net, is how outages are born.
Respecting stability is a virtue. The mistake is treating it as the only virtue.
Where the saying goes wrong
The phrase hides an assumption: that you can tell whether something is broken. Often you cannot. Code can work and still be quietly costing you:
- A function everyone is afraid to touch because nobody can predict its effects.
- A build that takes long enough that people avoid running it.
- A class that has grown a new conditional with every feature request.
- A dependency that no longer receives security updates.
None of these are failing right now. All of them make tomorrow's change slower and riskier. "Not broken" is a snapshot, but software lives in a film.
Broken versus brittle
A useful distinction: broken means it produces wrong results today. Brittle means it works today and will fail when something changes. The first is fixed because users complain. The second is fixed, if at all, when someone chooses to. Teams who wait for brittle to become broken do their repair work during an emergency, which is the most expensive time to do it.
Improvement without drama
You do not need a heroic rewrite. The approach that works is small, frequent and safe.
1. Put a safety net first
Before touching code you are afraid of, pin down its current behaviour with tests, even ugly ones that simply record what it does today. These are sometimes called characterization tests. If the code is hard to test because it calls the clock or the file system, techniques from isolating code with Moles and Fakes can get you started on legacy code before you restructure it.
[TestMethod]
public void Discount_for_gold_customer_is_ten_percent_today()
{
var result = new PriceCalculator().Discount(CustomerType.Gold, 200m);
Assert.AreEqual(20m, result); // records current behaviour, right or wrong
}
2. Take the boy-scout rule seriously
Leave each file slightly better than you found it. Rename one confusing variable, extract one method, delete one dead branch. Small steps, each shippable on its own, compound.
3. Refactor in the same change as the feature, but in a separate commit
Make the area easy to change, then make the change. Separate commits keep reviews readable and let you revert one without the other.
4. Make improvement visible
Track the things that signal brittleness: time to build, time to run tests, number of places a typical change touches. You do not need precise numbers to notice trends.
Deciding what to leave alone
Not everything deserves attention. A reasonable filter is to ask four questions about any candidate:
- How often does this code change? Rarely touched stable code can stay as it is.
- How bad is it when it fails?
- Does it slow down work in neighbouring areas?
- Do we have, or can we cheaply get, tests around it?
Code that changes often, matters a lot, and slows people down is first in the queue. A dusty utility that works and nobody edits can honestly follow the old saying.
Changing the conversation
When someone invokes the phrase, translate it into a question: "What would we need to be sure that changing it is safe?" That moves the discussion from fear to preparation. Often the answer is "tests" or "a way to roll back", both achievable.
It also helps to remember that code you decline to improve is still a decision. The same attitude shows up in the temptation to start over, covered in why total rewrites usually disappoint, and in the culture of learning from mistakes in failing enough.
A balanced rule
Here is a version you can live with: if it isn't broken, don't change it blindly. Understand it, protect it with tests, then improve it in small steps as you work nearby. Stability and progress are not opposites. Safe change is how stability is maintained over years.
More .NET guides
- Moles and Pex: Isolating .NET Code and Generating Tests (Now Fakes and IntelliTest)
- Building a Web Framework Is the New Black
- Funcy Testing: Using Func and Action Instead of Interfaces
- MEF: Making Extensibility Fun
- A Gentle Introduction to WCF
- Tinyweb Series, Part 1: Getting Started
- Tinyweb Series, Part 2: Building APIs
- Tinyweb Series, Part 3: Dependency Injection and Filters
- Tinyweb Series, Part 4: Views, View Models and Model Binding
- Tinyweb Series, Part 5: The To-Do Demo
- The Ordered Jobs Kata: Dependency Sorting with TDD in C#
- JavaScript: It's Up Your Sleeve
- C# News from the Future: What If...?
- What's After Unit Testing?
- Are You Failing Enough?
- Don't Bother Rewriting It: The Case for Gradual Refactoring
- Was Dave a Genius? Lessons from a Legacy Codebase
- Preston Tweetup: Why Developer Meetups Matter
- How Developers Really Learn
- Sustainable Side Projects: Keeping Personal Code Alive
- Parallel.For and Silver Bullets
Looking for a software partner? Browse the independent directory of French tech companies (web agencies, IT consultancies, software publishers; the directory itself is in French).