I’m working on an application (hobby project, solo programmer, small-medium size), and I have recently redesigned a significant part of it. The program already works in it’s current state, but I decided to reimplement things to improve the OO design.
I’m about to implement this new design by refactoring a big part of the application. Thing is I’m not sure where to start. Obviously, by the nature of a rearrangement, the moment you change one part of the program several other parts (at least temporarily) break. So it’s a little ‘scary’ to rearrange something in a piece of software that already works.
I’m asking for advice or some general guidelines: how should I approach a significant refactoring? When you approach rearranging large parts of your application, where do you start?
Note that I’m interested only in re-arranging the high-level structure of the app. I have no intention of rewriting local algorithms.
7
Rewriting a complete application just because you don’t like the code is usually not a good idea. Refactoring just for the sake of refactoring usually doesn’t fix any problems, but introduces several new ones.
When you’ve learned something new which would totally improve the design of your previous application, resist the urge to rewrite it. There will always be a next project where you can apply your knowledge.
The only situation where large-scale refactoring makes sense is when you try to add a new feature, and you realize that the current architecture doesn’t allow to do it in an elegant way. Then you might consider to do the necessary rewrites while developing that feature. Just don’t forget about your goal: Getting that feature to work.
2
Spend most of your time up front writing comprehensive and detailed unit and integration tests. They are the piece that will tell you if changes are breaking other pieces.
Then change pieces in a small a step as possible and run all the above tests, plus manual testing, between each step.
For the changes being made, use a distributed version control system like git so you can apply and rollback changes.
3