Development · English usage comparison
Refactor vs Rewrite: English Usage Guide for IT Professionals
"Refactor" means improving existing code's structure without changing its behaviour. "Rewrite" means replacing the code from scratch. Refactoring is incremental and lower-risk; rewrites are high-risk and often take far longer than estimated. Engineers use these words precisely — confusing them triggers strong reactions in code reviews.
Side-by-side comparison
| Aspect | Refactor | Rewrite |
|---|---|---|
| Code fate | Improved, kept | Discarded, replaced |
| Behaviour change | None — tests must still pass | Potentially significant |
| Risk level | Low (incremental) | High (unknown unknowns) |
| Typical duration | Hours to days | Months to years |
Example sentences
Refactor
- "I refactored the payment module to extract the validation logic into a separate function — tests still pass."
- "We refactored the API layer incrementally over three sprints without any service interruptions."
Rewrite
- "After five years of patches, we decided to rewrite the billing service from scratch in Go."
- "The rewrite took 18 months instead of the estimated 6 — classic second-system effect."
Exercises: choose the correct English usage
Select the best answer for each question, then check your reasoning.
1. "I improved the code structure without changing functionality." This is a ___.
Explanation: "Refactor" specifically means improving structure while preserving behaviour.
2. Which word fits? "We decided to ___ the entire authentication system from scratch in a new language."
Explanation: "Rewrite from scratch" means replacing the code entirely.
3. An engineer says "I'm refactoring this function." What should NOT happen?
Explanation: Refactoring must not change external behaviour. If the public API changes, it's not pure refactoring.
4. Which sentence uses the correct collocation?
Explanation: Refactoring a monolith into microservices is accepted usage — it changes structure but preserves behaviour. "From scratch" belongs only with "rewrite".
5. Which is lower risk?
Explanation: Refactoring is incremental and testable. Rewrites discard accumulated knowledge and typically take much longer than planned.
Frequently asked questions
What is the strict definition of refactoring?
Improving the internal structure of code without changing its observable behaviour. The formal definition comes from Martin Fowler's book "Refactoring".
When is a rewrite justified?
When the codebase is genuinely unmaintainable, the technology is end-of-life, or performance requirements can't be met by incremental improvement. Even then, an incremental strangler-fig migration is usually safer.
What is the "second-system effect"?
The tendency for rewrites to become bloated because engineers try to fix every previous flaw at once. Coined by Fred Brooks in "The Mythical Man-Month".
What does "refactor ruthlessly" mean?
Continuously improving code as you work — not waiting for a dedicated refactoring sprint. A common Agile / XP principle.
Can refactoring break tests?
A true refactor should not break tests. If tests break, either the tests were too implementation-specific, or you accidentally changed behaviour.
What is a "big rewrite"?
An informal term (often used with caution or irony) for a major rewrite project, frequently accompanied by "never again" stories about how it took 3x longer than planned.
What does "extract method" mean?
A common refactoring pattern: taking a block of code and moving it into its own named function, improving readability and reusability.
What is the "strangler fig" pattern?
Incrementally replacing an old system by building new functionality around it until the old system can be removed — named after the vine that slowly replaces its host tree.
What is "technical debt"?
The implied cost of future rework caused by choosing a quick shortcut now. Refactoring pays down technical debt; rewrites are sometimes triggered by too much accumulated debt.
How do you say "the code needs cleaning up"?
Natural phrases: "this code needs a refactor", "let's clean this up", "there's a lot of tech debt here", or "the code smell is too strong to ignore".