Back to Blog

That's Not a Refactor

October 10, 2026
RefactoringSoftware EngineeringCode QualityTestingWorkflows

Reviewing the PR is creative writing, testing it is pure superstition, and calling it a 'quick refactor' is an absolute crime.

That's Not a Refactor

The workflow migration is still going.

After weeks of debating which orchestration engine to pick—and somehow expanding the shortlist from two options to five in the process—we finally arrived at the part where you open an editor and touch actual code. Predictably, that's when someone suggested setting fire to the engine.

The task was supposed to be straightforward. In the middle of this workflow sits an operation that takes an incoming form payload, does a bit of processing, and emits configuration output for downstream services. There is very little real validation going on—mostly just taking whatever arrives, assuming the best of humanity, and passing it along. It's the kind of code that has survived multiple reorgs not because it was well built, but because nobody wanted to touch it. Just quietly accumulating code rot in a forgotten corner of the repository, doing its job as long as nobody made eye contact.

Naturally, downstream consumers needed a different data shape. A completely reasonable request: update the operation's output to follow a new schema. A modest contract update.

So I did what any engineer used to keeping production alive would do: I updated the output, kept the existing inputs intact, adapted the internals, made sure the test suite was green, and put up a tidy pull request.

Then came the feedback in code review:

"While we're updating the output, why didn't you do a proper refactor? We should update the input model to something completely new as well, and rewrite the internals from scratch so there's zero trace of the old schema."

I stared at the comment, paused, and took a long sip of water. Because in that sentence, the word "refactor" wasn't just doing heavy lifting; it was competing in Olympic weightlifting.

You Keep Using That Word

Somewhere along the way, our industry turned "refactor" into software engineering's favourite Trojan horse. It has become the polite, professional phrase developers use when they actually mean: Looking at this existing code hurts my feelings, and I would like to spend the next two weeks rewriting it from a blank file.

Martin Fowler literally wrote the book on this. In Refactoring, he laid out a definition that is mathematically precise: refactoring is altering the internal structure of software without changing its observable external behaviour.

It is a disciplined, almost tedious technique built on tiny, behaviour-preserving steps. You rename a variable, you run the tests. You extract a function, you run the tests. You move a responsibility, you run the tests. The tests stay green the entire time. To anyone calling the code from the outside, nothing changed.

Notice what's missing from that definition?

Changing the output is not a refactor. That's a breaking contract change.

Changing the input is not a refactor. That's another breaking contract change.

And throwing out the internals so you can drop legacy schemas while swapping both boundaries simultaneously isn't a refactor either. That is an outright rewrite. A big bang, dressed up in the respectable language of code hygiene.

The Problem with Moving Both Goalposts

Imagine your car's alternator starts squeaking on a Saturday morning.

The sensible, sane move is to replace the alternator, put the belt back on, and turn the key. If the engine doesn't turn over, congratulations: you bought a defective alternator or forgot to tighten the bracket. You have isolated your variable to exactly one component.

What was proposed on my pull request is more like walking into the garage, unbolting the alternator, pulling out the transmission, swapping the fuel injection for an experimental carburettor, and pouring racing fuel into the tank—all on the same Saturday afternoon.

When you turn the key and get nothing but an ominous metallic clunk followed by a wisp of grey smoke, where do you even start looking?

Did the starter solenoid blow? Is the clutch switch disconnected? Did the carburettor flood? Did you wire the ignition backward? Or did the high-octane fuel just melt your spark plugs?

That is what changing the input model and the output model at the same time does to software.

When an operation accepts an input, processes it, and returns an output, those two boundaries are your only anchors. If the output needs to change, that is your single moving part. The moment you decide to overhaul the input schema in the exact same pull request, you've cut both anchors.

When staging inevitably breaks—or worse, a downstream service quietly drops a provisioned payload at 3:00 PM on a Friday—what went wrong? Did the upstream caller construct the new input payload wrong? Did a missing field get swallowed because there's still no real validation? Did the internal mapping bungle an edge case? Or did the output serializer format a timestamp with dashes instead of slashes?

When every piece moves at once, debugging stops being engineering and turns into a murder mystery where every file in the git diff is a suspect.

The Boring Way That Actually Works

I realize this makes me sound like an engineering killjoy, but there is a way to do this that doesn't require emergency war rooms and caffeinated panic. It's not flashy, and it doesn't give you that thrilling dopamine hit of deleting 2,000 lines of legacy code in one glorious commit, but it has the distinct advantage of actually working.

The playbook is deliberate, incremental, and mildly paranoid:

1. Pin the existing behaviour down.
Before you touch a single line of logic, write characterisation tests against the current operation until you understand what it actually does—quirks and all. If the legacy code expects a string with three spaces on a Tuesday to avoid throwing a null pointer, you write a test verifying that Tuesday requires three spaces. You have to know what normal looks like before you try to change it.

2. Write a failing test for the new output.
Leave the input contract completely alone. Feed the existing input data into the operation and assert against the new output shape. The test fails. Beautiful. The universe makes sense.

3. Make it pass from the inside out.
Change the internal processing just enough to satisfy the new output contract. If that means writing a temporary translation layer or an internal adapter that looks a bit unglamorous, that's fine. Having an adapter in your codebase for a week feels like leaving a cardboard box unpacked in the hallway, but it keeps the test suite green. Downstream consumers can immediately start integrating against your new output in staging, and you know with certainty that the output contract is sound.

4. Migrate the input in broad daylight.
Only after the output is boring, stable, and proven in production do you look at the input. You introduce the new input schema, optionally supporting both shapes during a brief transition window. You write tests for the new input. You migrate callers one by one. And finally—with great ceremonial satisfaction—you rip out the old schema, delete the adapter, and pop the champagne.

Is it more steps? Yes. Does it require living with an intermediate state for a sprint? Yes.

Does it prevent a three-day post-incident review where three senior engineers stare blankly at Datadog trying to guess which of thirty simultaneous changes broke production? Absolutely.

The Big Bang Addiction

Why do teams push back against doing it this way?

Part of it is an allergy to transitional mess. Leaving an adapter or a deprecated schema in the repository feels like an admission of defeat. We want the pristine, greenfield codebase right now, consequences be damned.

The other part is organisational muscle memory. Some engineering orgs are simply conditioned to big-bang changes. A task gets scoped for two weeks, so someone goes into a cave for ten days, rewires three layers of the architecture, bundles four unrelated refactors and a schema overhaul into a single 4,500-line pull request, and dumps it on a reviewer with a cheery PR description: "Mostly just a quick cleanup 🚀".

Reviewing that PR is an exercise in creative writing. Testing it is pure superstition. Merging it is an act of blind faith.

And when everything predictably detonates in production, nobody ever questions the delivery method. Nobody says, "Hey, maybe changing the inputs, the outputs, and the guts in a single deployment was a terrible idea." Instead, the post-mortem concludes that what we really need is "more comprehensive end-to-end testing" and "longer QA bake times." We treat the symptoms while doubling down on the exact habit that caused the disease.

Call It What It Is

There is nothing inherently evil about rewriting a piece of software. Sometimes an old operation is so warped and calcified by years of conflicting requirements that trying to gently reshape it is like performing arthroscopic surgery on a statue. Sometimes you just need to bring in the wrecking ball and start fresh.

Just don't call it a refactor.

Refactoring is a precision tool. It is about safety, discipline, and keeping the system deployable at every single step along the way. When you change the inputs, the outputs, and the engine all at once, you aren't refactoring. You're rolling the dice on a big bang.

And in an org where everything already has a habit of breaking, maybe it's time we stopped giving the dice so much credit.