IT Glossary
What is code refactoring, and when is it done?
Same behavior for the user, code that is clearer and cheaper to change: that is what a successful refactoring looks like.
- 6
- sections
- 5
- questions answered
Refactoring is the internal restructuring of an application's source code — names, functions, modules, duplicated logic — without changing its observable behaviour: the application does exactly what it did, but the code becomes easier to understand and cheaper to change. In practice: bloated functions split into clear pieces, cryptic names replaced with telling ones, logic duplicated in five places gathered into one. The analogy is reorganizing a warehouse: not a single new product on the shelves, but every future order is easier to pick.
For a buyer, refactoring is the repayment mechanism for technical debt, and its effect shows in the cost of future changes: as a rule, code refactored at regular intervals takes new features in days, while code left to decay takes them in weeks, with collateral defects at every touch. Below: the definition from its source, examples, the right moment and how to put it in the budget.
Why it matters for your business
Future changes stay affordable
Regularly restructured code accepts new features in days rather than weeks — technical-debt interest never gets the chance to compound.
Fewer collateral defects
Clear, unduplicated logic means a repair in one place no longer breaks three others — the classic “works here, snapped over there” grows rare.
A transferable project, not a hostage
Refactored code is intelligible to any new team — switching vendors or growing the team no longer starts with months of archaeology.
What refactoring is and is not
The definition comes from Martin Fowler, in the book “Refactoring: Improving the Design of Existing Code” (first edition 1999, second edition 2018, with Kent Beck) and in his article “Definition of Refactoring” of 1 September 2004. As a noun, refactoring is a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior. As a verb, it means restructuring software by applying a series of such small steps.
What it is not: fixing a defect (that changes behavior), adding a new feature, or rewriting from scratch. Fowler stresses that refactoring is not “another word for cleaning up code” but a specific technique: small steps, each preserving behavior. When rewriting beats refactoring, see the dedicated comparison, listed under Related resources.
Refactoring examples
The most common steps: renaming a variable or function to one that says what it does; extracting a function from a long block; gathering duplicated logic in a single place; deleting dead code that nothing calls any more; splitting a class that does too much.
An invoicing example: the VAT calculation is copied into the invoice, the proforma and the credit note. You extract it into one function without changing any displayed total. When the VAT rate changes, you edit one place instead of three, and the risk of forgetting one disappears.
Code editors automate the mechanical steps: Visual Studio Code has Extract Method, Extract Variable and Rename Symbol (F2), according to its documentation. The decision of what to restructure and why stays with people, and tests confirm the result.
Want an estimate for your project?
Message us on WhatsApp. We reply the same working day, and the first 30-minute call is free.
When refactoring happens
Healthily, continuously, not as a campaign. Fowler notes it is often called the “camp site rule” (“Opportunistic Refactoring”, 1 November 2011): leave the code in a better state than you found it. In practice: before a new feature, to make room for it; when fixing a defect, after the fix has been made separately; during code review. In a monorepo, a rename touching several projects is done as a single change, tested once.
Signs that more is needed: estimates for small changes keep climbing, “we don’t touch that module” has become internal folklore, every fix spawns two new defects. And “we stop everything for three months to clean up” is a sign it was postponed too long.
For a business: budget and the question to ask your vendor
Targeted refactoring fits inside the annual maintenance budget: the benchmark for custom software is 15–20% per year of the development cost, indicative.
The revealing test question for your vendor: “when did you last refactor something in our project — and what?”. A team with concrete examples is maintaining your investment; one that never has is building, feature by feature, the museum of patches every future developer will flee.
Frequently asked questions
Why pay for work that produces nothing new?
Because what comes out is the speed and safety of every future delivery: refactoring is engine maintenance, not body tuning. Judge it on the trend: the cost of a comparable change today versus a year ago. If it keeps rising, you are already paying for refactoring, as interest, without receiving the cleanup.
How do I know refactoring won’t break something that worked?
Through automated tests that pin down behavior beforehand, small frequent changes instead of mammoth restructurings, and code review. If your project has no tests, step one is building the test net, then restructuring underneath it.
Can refactoring replace a full rewrite?
As a rule, refactor: in small steps under tests, because the application keeps working and the budget can stop after any step. A rewrite is rarely justified — unsupported technology, code that can no longer be covered by tests — and the full criteria are in the refactoring vs rewrite comparison.
Does refactoring fix bugs?
No, that is not its purpose: refactoring preserves behavior, existing defects included. Fixing a bug changes behavior, so it is done separately, as its own step with its own test. In practice, clearer code makes defects easier to find, and the team fixes them right after, in a separate change.
Can a code editor or an AI assistant refactor automatically?
Partly: editors safely handle the mechanical steps — renaming across a whole project, extracting a function or a variable — while AI assistants propose larger restructurings. What to restructure, in what order, and whether behavior stayed the same is decided by people and automated tests, not by the tool.
Let’s talk about your project
Book a free 30-minute call or send us an email. We reply the same working day.
office@northdan.com · +40 750 252 851