When is it better to delete code instead of refactoring it? #995
-
|
When dealing with legacy or poorly structured code, refactoring is often the default approach. In your experience, when does deleting and rewriting code become a better option than incrementally refactoring it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Deleting code becomes the better option when the cost of understanding it exceeds the cost of replacing it. Some signals I look for: The code has little or no test coverage and adding tests is harder than rewriting the logic. The original assumptions no longer match current requirements. Small changes consistently introduce regressions. In those cases, incremental refactoring tends to preserve accidental complexity. A focused rewrite, scoped tightly and protected by new tests, often results in simpler and more reliable code. The key is keeping the rewrite constrained rewriting everything at once usually recreates the same problems in a different form. |
Beta Was this translation helpful? Give feedback.
Deleting code becomes the better option when the cost of understanding it exceeds the cost of replacing it.
Some signals I look for:
The code has little or no test coverage and adding tests is harder than rewriting the logic.
The original assumptions no longer match current requirements.
Small changes consistently introduce regressions.
In those cases, incremental refactoring tends to preserve accidental complexity. A focused rewrite, scoped tightly and protected by new tests, often results in simpler and more reliable code.
The key is keeping the rewrite constrained rewriting everything at once usually recreates the same problems in a different form.