Veltos.Tech

Development

Refactoring

Also known as: code refactoring, code cleanup

Definition

Refactoring is changing the internal structure of code without changing its external behaviour: the functionality before and after is identical, what changes is readability, coupling and the cost of the next change, verified by tests and regression checks.

The defining condition is unchanged behaviour. If the application starts doing something new afterwards, that is development, not refactoring, and it should be estimated differently. Which leads to the key technical prerequisite: tests, or at minimum a reproducible verification scenario, must exist beforehand, otherwise there is nothing to prove behaviour stayed the same with. Typical moves are extracting a repeated fragment into a function, splitting a class that took on four responsibilities, deleting dead code, and reshaping a data schema around the scenarios that actually occur.

Selling refactoring to a client on the grounds of clean code is useless and, honestly, wrong. The conversation runs in terms of consequences: this rework exists so that adding a new delivery type stops taking two weeks instead of two days; this one so releases can go out during working hours without assembling the whole team; this one so connecting a second warehouse becomes possible at all. Refactoring needs a goal tied to specific upcoming backlog items, otherwise it becomes endless improvement for its own sake.

Two traps. The first is the big-bang refactor on a separate branch for three months: while the team rewrites, product work continues on the main branch, and the eventual merge becomes its own project with its own risks. Small steps, each of which reaches production, are far safer. The second is refactoring instead of deciding. If the architecture fundamentally does not fit the problem, cosmetically rearranging modules will not help: either change the architecture deliberately or accept that replacing the system is cheaper.

Related terms

Related services

Read more

Need this done, not just defined?

We do this work, not only write about it. Describe the task and we will scope it and send a staged estimate.