Refactoring

Refactoring is improving the internal structure of existing code without changing what it does — making it cleaner, simpler, and easier to maintain.

General Programming

Typical refactors include renaming variables for clarity, removing duplicate code, and breaking a long function into smaller ones. Good tests give confidence that behaviour stays the same.

Examples

Python

# Before
print(2 * 3.14159 * 5)
# After: clearer and reusable
PI = 3.14159
def circumference(r):
    return 2 * PI * r
print(circumference(5))

Output:

31.4159
31.4159

See also

Back to the Dictionary