Skip to main content

Cost and Scope

Refactoring

Refactoring changes how code is built without changing what it does, which is exactly why it needs a business reason attached before you fund it.

Definition

Refactoring is restructuring existing code without changing what it does from the outside. The screens and output stay as they were; only the internals change.

What It Actually Means

That definition contains the entire commercial problem with refactoring, which is that a successful refactor is invisible to you. You fund a fortnight of work and receive a product that looks and behaves precisely as it did before. There is no demo. There is nothing to show the board.

That makes it hard to judge, which is a different thing from wasteful.

Why You Are Hearing About It

Refactoring is proposed when the shape of the code has stopped matching the shape of the problem. That does happen. A system built to handle one type of customer, then stretched to handle four, ends up with the fourth type held on with tape. Every change to it is slow and risky, and the honest fix is to restructure rather than add a fifth layer of tape.

It is also proposed because developers find working in tidy code more pleasant than working in untidy code. That is a legitimate preference, but on its own it gives you no business case.

The distinction matters because both arrive in the same sentence: “we should refactor this first.”

Legitimate Or Not

Refactoring earns its cost when it is attached to something you were going to do anyway.

“We need to add multi-currency, and the pricing code assumes one currency in nine places, so we restructure that part first” is a strong case. The refactor is scoped by the feature, it has a boundary, and you can tell when it is finished because the feature ships.

“We should refactor the codebase before we do anything else” is a much weaker case, because it has no boundary and no completion test. Refactoring without a destination expands to fill whatever time it is given.

The size is the tell. Refactoring scoped to a feature is measured in days. Refactoring scoped to a codebase is measured in months, and is usually a rewrite that has been given a gentler name.

What To Ask

  • What are we about to build that this makes possible or cheaper? If the answer is nothing specific, it can wait.
  • How will we know it is done? A good answer names a feature that ships or a behaviour that stops happening.
  • What is the risk of breaking something that currently works? This is the real cost of refactoring, and the answer should mention tests.
  • Could we do this as part of the next feature rather than before it? Very often yes.

The Question That Settles It

One question separates careful refactoring from risky refactoring, and it is worth asking every time: what stops this from breaking something?

Restructuring code that has automated tests around it is a controlled activity. The tests confirm behaviour has not changed, which is precisely what a refactor promises. Restructuring code with no tests is not refactoring in any meaningful sense. It is rewriting and hoping, and the bugs surface weeks later in places nobody connects to the work.

If someone proposes a significant refactor and there are no tests, the first piece of work is writing the tests, because they are what makes the rest of it safe.

Refactoring is how technical debt gets paid down incrementally. It is not the right tool for an ageing platform, where the constraint is the technology itself rather than the structure of the code.

More terms are in the glossary.

Portrait of Alexander De Sousa, founder of Digital Royalty
Founder-led
“I’ve put everything I know into how this company works — the standards, the method, the care on every project. It runs through the whole team, and I hold us all to it.”

Alexander De Sousa · Founder LinkedIn

Featured on BBC Radio Solent

Get started

Tell us what you need

A few quick questions, then a straight answer from a real person — usually within a few hours.

What happens next

  1. 1 We reply A real person reads your answers and gets back to you, usually within a few hours.
  2. 2 Questions or a short call If anything isn't clear, we ask by email or book a short call. Before any call we audit your website and make the quick fixes it finds, free.
  3. 3 Your fixed quote A clear, fixed price in writing, within 48 hours of any call. There is no obligation to go ahead.

Tell us what you're working on

Whether it's a new site, a platform, or a process that shouldn't be manual any more — we'll tell you honestly if we can help.