Reasons to Rewrite your Code

Recently I have been learning ReactJS, starting with the very basics. It’s my first frontend javascript framework and thus has been a bit of a difficult process to understand what exactly was going on. I had to learn all the different paradigms and strategies used in frontend development as well during this time, so I have had plenty of time to look over my code and rewrite it to get it done right. Let me give you some of the most compelling reasons one should audit and rewrite their code often.

Using my React experience as an example, I’ll start off with staying on the cutting edge. When I first wrote React code I used classes and eventually learned how to integrate Redux into my React classes. As it turns out, recently a breakthrough has been made into writing React components as functions instead of classes, alleviating issues that come with dealing with classes in javascript as well as long standing problems with React structuring. This means the code I was writing was already obsolete since most of the tutorials available that I was using were using classes. Nonetheless, I took it upon myself to relearn the syntax of using functions instead of classes for my components and haven’t looked back. The code I write now includes much less boilerplate and is easier to debug than before. Integrating with Redux is also super easy since there are hooks in place for pretty much any application. If I ever feel the need, I can also write my own hooks which provides a whole new level of flexibility. 
Rewriting my code using functions as components has also allowed me to take an in-depth look into my code and see where I have been inefficient and where I made subtle mistakes. By doing this audit I could take a fresh look at the problems I was trying to solve and decide whether or not my initial approach was acceptable. I could also take a look at the overall architecture of my code. Maybe I felt that by the end of the project I had planned it poorly and some things I hadn’t accounted for had created needless complexity, or maybe I had made it difficult to implement a certain component into the project. Either way, I could now fix this issue and internalise the steps that I can take to avoid facing it again in the future.

Finally, rewriting code can be a good tool for vanity. Maybe you’re feeling a little bit of impostor syndrome and have been having difficulty grasping some concepts recently. Taking a look at an old project and rewriting some parts of it with the new skills you’ve learned in the meantime is a great way of visualising your progress. You will literally see the improvements you’ve made and if you made any glaring mistakes, the performance of your application can even improve visibly. It’s always a good feeling to look back on your code and see that it is readable and maintainable and if you were to drop in another developer in your seat, they could understand what you were doing reasonably quickly.

Rewriting code can seem like a useless exercise to some, but it is one of the easiest ways to see your personal improvement and to stay on the cutting edge. If you’re learning something new and are uninspired to write a new project, you can merely edit an old one and apply the new concepts to that! Give it a try and maybe you’ll be surprised.