Kent Beck makes the following observations, in Martin Fowler’s book, Refactoring:
- Code that is hard to read, is hard to understand and consequently hard to modify.
- Programs with duplicated logic are hard to modify.
- Programs that require additional functionality that requires changes to existing code are hard to modify.
- Code containing complex and convoluted conditional logic is hard to modify.
When should you refactor?
- When you add functionality.
- When you need to fix a bug.
- When you perform code reviews.
When shouldn’t you refactor?
- When you really need to rewrite from scratch!
- When you are close to a release deadline.