Legacy Code: It's an Inevitability

iamboris's picture

Something I've been thinking on lately, and it's tied to my day job. This job is my first real gig as a software developer. I've been really enjoying it, but there are some things that were unexpected about working with others' code. In particular, when you work on an outdated system or platform it's even more difficult. This is often referred to as legacy code

It's particularly difficult to work with. There will be kinks and quirks in the system. It will take a long time to figure out. "How is this working?" and "what the hell are those variables used for?" are common questions I have when looking at code. "Awesome! They're using the letters pp as a variable! What does that even mean?!" 

If you are lucky enough, someone around knows what it does or maybe there is a USEFUL (I cannot emphasize that enough!) design. Otherwise, you'll be debugging for a long time, you'll make a change that should work, but then doesn't or breaks another part. The result is often this. Often times in legacy code there is a reason why things are the way they are, but you won't have an explanation up front.

Add on top of that operating systems add in more support for character sets, file types, etc., it just can be a mess. This is generally why your old games may not function quite right on new hardware. A lot of the time though, companies are pretty good at not breaking past functionality, just don't look at the source code FOR THE LOVE OF GOD!

The significance of this post is to give people a heads up that at some point as a developer you will do this. You won't do this in school. It takes a different skill set than what they generally teach in programming classes where a lot of code is written from scratch. With legacy code you deal with existing objects and classes that can't be refactored too much without mayhem and panic. 

Personally, I actually enjoy this part of my job. Like solving a dungeon puzzle in Zelda, you learn the rules of the area then act within that rule set to find the key. Those are some of my happiest moments in my work. Making new stuff is more fun, but be aware that you or someone else will be dealing with your code in the future. 

Future problems image
"That's future sucker's problem"

Don't be like that. It's shortsighted and there will be much sadness and anger in the future. Don't get me wrong, you'll grow a ton. When you come back and look at old code most of the time thinking, "What the hell was I on when I wrote this? Was I drunk or blinded by exhaustion from toddlers?" That's normal, and it means you're learning. 

You really can't always plan for the future, but do your best to make your code legible and maintainable. You will deal with this. It will be okay. It's an acquired skill that will make you valuable. Please keep that in mind and follow the golden rule:

"Do to others as you would have them do to you."

Happy coding!

- Boris