I was recently working on a pretty big set of changes in the existing codebase to implement new features and modify UI. Before I started working on that I noticed it will demand a lot of work and started considering if I should try to refactor the existing codebase or simply write it from scratch. I finally rewrote a significant part of the codebase and I’m happy with that, but before that, I actually spent a few hours thinking about it and writing all pros and cons of both solutions, so I decided that it might be worth sharing my thoughts about refactoring vs rewriting. Ok, let’s start.
First, let’s talk about refactoring and rewriting in general. Big redesign or significant changes in app logic usually demand a lot of changes in the code, and as a result, are pretty obvious moments in which we realize we have to do something with our codebase. Even if you don’t have one big change to be done there are some warning signs which should force you to at least consider doing something with your existing codebase:
First is the most obvious one, a lot of legacy code – commented code, unused variables or methods, especially a lot of comments explaining why something is done in a way that is not obvious. This is funny as after a month even you will not be able to understand your own code without those comments.
Another ‘aha’ moment might be the one when you realize that adding even a small new feature takes a long time in the existing codebase and as a result usually nobody in your team wants to work on that. This is a warning sign more for a manager, but if you notice that you can at least use it as an argument to get some time to work on cleaning up your code.
Last but not least are problems we simply cannot solve with the existing codebase. The most common one is the technology stack getting older and older, and more and more problems are generated by that. No support for new versions and features of OS, abandoned 3rd party libraries, or the old syntax of programming language, there are many possible problems caused by that. At some point, even performance can be crappy and you simply cannot improve it with the current stack.
The more annoying get the code the easier is to consider everyone even yourself that You simply need to do something with that 😉
Ok, let’s talk about why it’s actually worth rewriting the existing codebase from scratch.
First and foremost… completely new and up-to-date architecture, languages, and frameworks can be used. As a result, you will be able to use new features and syntax offered by the modern toolset. This also means you will be also no longer blocked by things that are missing in your current language or framework version. Don’t forget that it will be also easier to find developers who want and can work on this app, as developers simply love to work with up-to-date languages and frameworks, you will no longer be the only person on the team who knows this crappy code.
Another good argument to rewrite code is that it usually leads to faster development of new features, mostly because logic can be simplified and adjusted to current needs, it no longer needs to support old use cases which are no longer there, but someone simply forgot to remove part of the logic which was used 3 years ago.
A very important advantage of writing from scratch code for the existing apps is that old mistakes can be avoided – after maintaining the app for some time everyone in the team knows what’s the weakest point of it, using that knowledge can help to avoid the same mistakes to be made again
Actually, if you are planning to rewrite the codebase from scratch and there is no redesign included, feel free to ping product people and UI/UX team, as this is actually a great moment to completely redesign the app, everything will be written from scratch anyway.
Last but not least, rewriting the app is also, a good moment to analyze which features were really used by the end-users, and thanks to that you can simply save time on implementing those which were not used at all.
Ok, as usual, there are not only advantages of rewriting the codebase, let’s talk about potential problems.
First and foremost this will cause a shorter or longer pause in feature development – rewriting your app from scratch means you will be most likely not able to add new features to the existing one, which will give your competitors some time to catch up or leave you behind, also your existing users might not be very happy with that, you can of course assign 1 or 2 devs to maintain existing app but because of that the cost of the rewrite will only get higher and might be hard to explain especially for the business-focused part of your company
Another ground truth is that rewriting the app is not a cure for all its problems, even if you do your best, old and new bugs will come to you – maintaining the app for some time means your team most likely spent a lot of time to fix bugs, as a result even the app is old it’s probably stable and usable (otherwise you would not have a budget to rewrite it). Rewriting it from scratch will for sure cause some old and new bugs will be exposed and will demand time to fix them before users will be able to benefit from using it.
Ok, we now know some of the pros and cons of rewriting the app from scratch or at least rewriting some significant part of it. It is a very difficult decision to make and we must remember that each case is different. But if you are only able to do it I would highly recommend updating out-of-date code as working with a fresh codebase and modern tools is not only easier but simply more enjoyable. If you have some other opinions about rewriting the codebase feel free to share them in the comments section, see you next time bye!
Leave a Reply