Code refactoring is improving readability and reduces complexity.
Don’t waste time to write perfect codes. As a developer, writing clean code will come naturally. Many years ago, I hired a developer who loves writing perfect code. He spends weeks to refactor something that is already working and readable. Unfortunately, it’s not worth the money and time spent on it.
No developer can write perfect code. Don’t refactor because you are afraid of criticism from other developers. Learn how to be a better developer by learning from criticism, failure, and mistakes.
“When I talk about refactoring, I’m often asked about how it should be scheduled. Should we allocate two weeks every couple of months to refactoring? In almost all cases, I’m opposed to setting aside time for refactoring. In my view refactoring is not an activity you set aside time to do. Refactoring is something you do all the time in little bursts. You don’t decide to refactor, you refactor because you want to do something else, and refactoring helps you do that other thing.”
― Martin Fowler,
Refactoring can break the working code. It’s very important to write test code before refactoring.
When is a good time to refactor?
Clean code matter and refactoring can improve code quality and productivity.
- Speed up development process without losing control
- Adding new feature
- Fixing bug
- It’s cheaper than rewriting
I am a fan of small refactoring to keep code clean and maintainable.