Compressed Thoughts

A blog by Matthew Rease

html code on a green crt display

Old Code

Ever look at your old code, and think: what the actual ****?

I've been programming for ~5 years now, and sometimes I like to go back to old projects. Either to, take a look at what I did, port them in some way to a better platform (or just for the sake of renewing them), or even continue working on them in some cases! But there's one big problem that always pops up...


MY OLD CODE SUCKS!

And I have a sneaking suspicion that I'm not alone here. For the most part, old code I've written falls into one of two categories (if not both): 1. it's written in a very beginner way, which is to be expected since that's when I began coding, and there are clearly much better and faster ways to do it, and/or 2. it's just terrible in general, usually to the point of taking me hours to actually understand what ~20 lines of code even do, because I left 0 documentation, and the code was just written in a way where you'd have to have been in the time-period you were writing it, to ever remember it fully.

One of my favorite examples (which I may upload/post later), is some old C++ code, from when I first started making software for the 3DS Homebrew Community. As programmers of C++ will know, it is not only an object oriented language, but one with classes. Taking my code from the first link (Breakout), I do indeed use classes in my program... oh boy do I use classes... First of all, I'm fairly certain I had a nested class in there somewhere, as well as a ton of classes being inside int main(). Now sure, does the code "work". Well yes, at least in that regard it works.

"So what's the issue?" I hear all you non-programmers asking. And honestly, it's hard for me to answer that question - it's the kind of thing you really need to experience first-hand to understand, but I think I can try to make an analogy: let's say you write a short novel (as I'm sure many of us have tried at least once, even if we immediately gave up), and then come back in like 5 years when you're much smarter and much more mature (assuming you wrote this at a younger age). You're going to sit down, read your novel, and cringe in so many ways. Bad writing, bad grammar, bad structure, bad everything. Sure the story is still the same as it was back then, but now you realize how bad it actually is. That's kinda what it's like to go through old code.

Now, what's the point of all this? I don't know. I just felt like talking about it. I don't need a reason! In all seriousness, I think it's something that new programmers need to be aware of. It's nearly impossible to avoid this happening, but you can mitigate it. When you're online, looking through forums and whatnot, heed the advice of others. When they say something like "you can do it this way, but you should do it this way", chances are they're probably right.

And to all my non-programmers out there, damn, thanks for reading this far, I'm curious how well I got my points across to someone on the outside. Can you think of better analogies for old code? And again, thank you for reading everyone, and I'll be back soon, hopefully with something a bit meatier.