Saying hello to your old code
Tags: typescript
Published: 2020-05-26 19:43:46


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](https://www.typescriptlang.org/)  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](https://github.com/areknawo/eslint-config-xtrict)  that I've developed and started using a while ago after  [this post](https://areknawo.com/creating-the-perfect-eslint-config/).

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](https://twitter.com/areknawo),  [Facebook](https://facebook.com/areknawoblog), or here on Dev.to. Thanks for reading this piece!

<a href="https://www.buymeacoffee.com/areknawo" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="height: 25px !important;width: 100px !important;" ></a>