# Refactoring

> A change to how code is written. What it does stays the same.

**Field:** Software Development  
**Category:** Testing & Quality  
**Also known as:** Refactor, Code Refactoring

## Think of it like

Think of it like tidying your room. All your things are still there, just easy to find.

## Definition

Refactoring is changing how code is written without changing what it does. You might rename a confusing name, split a long function or remove copied code. The program gives the same results before and after. Tests prove that, so it is much safer with a good test suite. Small changes made often keep code easy to change.

## Example

Emma's 200-line function is hard to read. She splits it into five short functions with clear names, and all her tests still pass.

## Why it matters

Code is read far more often than it is written. Tidy code is faster to fix and safer to change.

## Common mistake

Refactoring and adding a feature in the same change. If something breaks, you cannot tell which part did it.

## Three principles

- **Same behaviour.** Only the shape changes.
- **Tests keep it safe.** They prove nothing broke.
- **Small and often.** Not one big rewrite.

## Related terms

- [Code Smell](https://learn.benibix.com/term/development/code-smell)
- [Technical Debt](https://learn.benibix.com/term/development/technical-debt)
- [Test-Driven Development (TDD)](https://learn.benibix.com/term/development/test-driven-development)
- [Function](https://learn.benibix.com/term/development/function)
- [Find All References](https://learn.benibix.com/term/development/find-all-references)

---

Source: https://learn.benibix.com/term/development/refactoring
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
