Staying on Track with Code Refactoring
Recently, I was asked to refactor a React app from JavaScript to TypeScript. On the surface, it seemed like a simple task. I had a clear plan in place:
- Add missing tooling to enable more maintainable and efficient development in TypeScript.
- Gradually migrate JavaScript files to TypeScript with a new folder structure and pattern.
- Refactor implementation.
- Refactor the UI.
I thought this would be a straightforward process, but I soon learned that the biggest obstacle was actually psychological. As I began refactoring, I found myself getting sidetracked by disorganization or flaws in some implementations, and I would start refactoring those areas without sticking to the plan. This caused the scope of the project to become bigger and bigger, and I ended up spending more time fixing bugs than I had intended.
I am now working on controlling this tendency and reminding myself to take things one step at a time and stick to the plan. It's important to recognize that psychological factors can be just as much of a barrier to writing code as technical ones.