DEV Community

Cover image for Saying hello to your old code
Arek Nawo
Arek Nawo

Posted on • Originally published at areknawo.com

Saying hello to your old code

We've all been there, haven't we? Looking at our own code written days, months, and maybe even years ago. Now, I'm not talking about some kind of enterprise codebase, Cobol, or stuff like that - these are beyond my comprehension. ;) I'm rather talking about things like personal projects or products - code that you've written yourself and have all the rights to change it.

What's the problem?

So, what's the problem with looking at our old code? Well, if you've done it before you'd most likely know. It's this weird feeling - almost frustration with how could one could have created such "monstrosity". The thing is most programmers looking at their past dealings are fast to identify issues in them, for which most of the time the only "rational" solution is a complete rewrite. "I could have documented it better", "I should have used a different pattern/architecture", "This code isn't clean enough", etc. I don't know how to best describe it - it's just something within me that turns on immediately when I get in contact with my old code - something that snaps just like that.

How does it feel?

My personal experiences aren't with very old code - no. In fact, recently the oldest piece of code I've come in contact with was my personal side project from a month ago. And yet something as "young" as that made me think.

The first thing I did even before touching the code, was reminding myself of its structure. It wasn't very hard, because, as I've said, I wrote that code only a month ago. But, immediately when I did it, I started to deeply reflect on it. "This can be improved.", "How about a restructurization?", "I should change my storage solution", etc. - you see where this is going.

Usually, I'd just get depressed by how much could/should be improved, but this time was different. Before drowning in the vast pool of thoughts, I suddenly realized that what I was thinking about was unrealistic. Doing that would mean a complete ground-up rewrite of the entire codebase - something I only realized I didn't have time for, given all the new projects I had planned. So, I went ahead of myself and decided not to alter anything more than was necessary. And you know what? This actually turned out pretty good!

The solution

How I achieved this "peace of mind"? I didn't really know until I started to think about all this after the fact.

First, I realized that making so drastic changes to my old code is not a good choice for me right now. I've got no time nor resources to pour into the same project yet again.

Second, once I've actually got in contact with my old code, I saw that it wasn't as bad as I'd initially thought. The entire codebase was written in TypeScript and it was structured well enough that I could almost immediately start working. This made me very happy. The overall code style and documentation were also pretty good, mainly due to the extremely strict ESLint config that I've developed and started using a while ago after this post.

And lastly, when all edits were done, I realized that all the changes I wanted to make were not only unnecessary but also somewhat imaginary. I concluded that the code I had envisioned was kind-of "utopia", and that even if I went into that direction, I'd never achieved satisfying results. I'd just stayed in the loop - constantly "improving" my code.

Thoughts?

This is very much an open post, as I'd love to hear about your opinions, thoughts, and past experiences from dealing with your personal old code. Did you have similar thoughts? Did you manage to get out of the loop? Or is it only me who has such problems? Be sure to let me know down in the comments!

For more thoughts and reflections about web development and coding in general, be sure to follow me on Twitter, Facebook, or here on Dev.to. Thanks for reading this piece!

Buy Me A Coffee

Top comments (0)