Legacy Code

I remember the first time I heard the term “legacy code“. It was said with the implication that it was old, disliked, awful, God-help-you-if-you’re-sent-in-there-to-modify-it kind of stuff. That’s not really what it applies to, however. In many cases it’s really just code that’s not the most current stuff. It could be stuff that the previous guy wrote that you have to modify. And this is where I currently find myself.

I’m working on a project where the code was an internal application used by the folks who put together the parts that they make. It’s about three years old, written in Java, and contains almost no useful comments. The code is most definitely not self-documenting. It was put together by a summer intern with little actual coding experience and is a real mix of working, non-working, and perplexing code. Just upgrading to the latest java development kit has caused numerous warnings and exceptions.

I talked with the boss about what he wants done and then proceeded to take stock of what I’m dealing with. The UI isn’t terribly complicated other than a large table with lots of data and a few buttons mixed into the table. There’s some interesting functionality built into it (the table) and I’m trying to figure out if this is the best way to present this to the user or not. I’ve got a lot of leeway on how to proceed, but the requirement that it be done fairly quickly and cheaply.

After looking through the code in some detail, I have determined that the overall state of it is fairly “hacked”. It’s clear that the previous programmer didn’t understand why he was doing some things, especially related to event handling, putting icons into buttons, and computer graphics. So, in other words, there’s a lot of unnecessary code. The rest of the code is filled with uncommented, obscure variable names that are used, but of course, leave no indication of their job.

So, what’s a coder to do? I’ve tentatively decided to start by creating a new UI. I’ve discover Jaxx, which, although it doesn’t seem to be undergoing any changes and needs some updating for the latest jdk, does have some nice functionality and can help me get my project going quickly. This wasn’t an easy decision either, and I’m still second-guessing myself, but I figure that I can probably redo the basic UI with another similar toolkit in a few days, if necessary, for the next release.

With the new UI in place, I’ve been grabbing components of the code from the legacy application and moving it into the new framework I’ve built. So far, it has been a few days worth of work and I’ve got a much smaller, cleaner code base to work with. Already, the graphics are working better and there’s some separation of functionality into proper classes.

I plan to continue to grab code for the guts from the current app while cleaning it up, and adding some #!*!$%& comments and documentation. My decision might have been different if the circumstances were different. A clean, logical, well commented and documented code base would have led me to modify the current code as is. Notes on what wasn’t working yet would have helped. Since there was no source control used, I can’t even be sure that I have the latest code.

Am I making the right decisions? I believe so. I’ve made great progress in very little time and I’m reusing the existing code, so I’m not reinventing the part of the wheel that seems to be working.

What legacy do I plan to leave for myself and/or the next person who takes over the code?

  • I will comment the code and not assume that it’s so beautiful that it’s immediately intuitive. I’ll likely be the beneficiary of this a couple of months down the road.
  • I will use some source control, so I can know where the latest code is and do release control.
  • I will track working and non-working functionality.
  • I will spend time to think about the best way to accomplish the tasks at hand by doing diligent research and design.

I hope that this will lead to more interesting projects in the future with the successful delivery of this one. Doing good work leads to more work.