Phil Giles

old code, new tricks

Revisiting your code can sometimes be a bit of a daunting experience, especially when your next task will add new functionality that overlaps with your old code or the first draft was a prototype that was more thrown together than carefully crafted. I recently had to revisit an app that I had written, and all of these worries hit me straight away!

The task was simple. Replicate some existing functionality in a new view passing in some different data. Having written the original code I knew that there were a lot of complexities in this app, and making its functionality more granular and reusable to more views could become a bit of a refactor.

However, when I opened up the codebase to give some estimates on the work I was pleasantly surprised. It turns out I had taken the time to write the code in a modular, fairly reusable way already.

I actually had to look over the code a few times as I couldn’t believe it was going to be quite so simple! There was obviously work to be done to get everything perfect, but the size of the work had shrunk massively from what I had imagined at first.

One of the big contributors to the ease of code refactoring in this case was the single responsibility principle. Writing modular code that only cares about what it does, makes changes and refactors much more simple and moving around code becomes a breeze!

Another great thing that came out of this experience is a bit more self-confidence in writing code. Opening up your code and it being almost exactly how you think it should be, gives you a bit of a “wow I can’t believe I wrote that” moment. And it feels good!

I guess what I’m getting at is that taking a bit more time now really can save you in the future. With the ever-changing nature of the web, and all the new great ideas we have to improve our apps this couldn’t be more true! And that’s how I will try to approach all my code from now on.

If you enjoyed the read, drop us a comment below or share the article, follow us on Twitter or subscribe to our #MetaBeers newsletter. Before you go, grab a PDF of the article, and let us know if it’s time we worked together.

blog comments powered by Disqus