While preparing for a webinar about static analysis the other day, a colleague and I had a very interesting discussion about legacy code, in that it’s often thought of as just “old code” but really means more than that. See my latest vlog on YouTube:
Transcript
If you don’t have time to watch the video, or prefer reading, here’s the transcript:
Legacy code. What on earth is legacy code? What does that mean?
To me, this is another one of those funny words that in software development has somehow over time lost all of its meaning. Is it just old code? Or is it something rare and valuable? So let’s take a look at that. Let’s talk about legacy code.
So the other day, I was working on a presentation with a co-worker. And we were trying to decide exactly how to use static analysis with legacy code. Because of course, as we all know, every working system has a bunch of old code that’s been there for years and years and years. And I was prepared to simply have a quick slide that says, hey, look, old code, deal with it differently. You can’t treat it the same way you treat new code. And if you want to look at that, I’ll put a link down below how to go find that session if you want to learn more about it, but the basic idea was in my mind that legacy code is just, you know, code that’s been around a while.
And my co-worker said, no, we need to define what legacy code is. I can see now that the Canon camera has completely died on me for unknown reasons. Oh, well. So, my co-worker said, no, legacy code doesn’t just mean old code. And we need to define what it is so that people will know what it is.
In fact, well, what is it? Right, like, why is it that I think legacy code is just old code? So I started putting together my slide and I went on to stock image site looking for cool things that would define what is legacy like I usually do. Trying to find something silly. And of course, you have to be careful because when you’re searching the internet for images, it always ends up at the same place. No matter where you start. We know that so be careful. But what I found quickly was that a lot of things for legacy code ended up with something like this.
Where legacy is a bequest, like a will, it’s a gift from beyond. And I thought that’s pretty interesting because legacy code isn’t necessarily just old code. Legacy is something that someone left you before they moved on. And so legacy code can mean code that you no longer have the owner to or the author to.
And so I thought, that’s pretty interesting. Because when I think about legacy, I want to think about a bequest, I think about a will. What was I left? On one hand, it might be something amazing. It’s a big old pile of cash and I can use that for anything that I want. Very valuable, can be used for absolutely anything. So it’s extremely useful, flexible, and things like that.
On the other hand, I could be left something really awful. Maybe I was left an old bird. This parrot this cockatoo might outlive me, this thing might be five years old and gonna to live to be 75. And I’m going to have to take care of it for the rest of my life. It might be, that this bird has some kind of ailment, and the same is true of any other pet. Maybe it’s got problems, and you’re going to have to pay for them.
So not only have you making an investment for the rest of your life, but you’re going to have to pay doctor bills on this thing. And sometimes legacy code is like that. Sometimes the legacy code we’ve been given is something that we should more properly find a new home for. Sometimes legacy code is super valuable.
It’s funny because when you look at almost any organization that’s been around for a few years, you’ll find out as you talk to people, there’s that one piece of code least, that everyone is afraid of touching. They’re afraid of touching it because it’s complicated, no one understands it. The person who wrote it is long gone. That’s what makes it legacy. It was their gift. And everything relies on it. And it’s super easy to accidentally break it. These are the big problems with legacy code. Sometimes legacy code might be something like a house and you look at it, and it looks pretty good. And you think, hey, this is a useful house. I can take this house, and I can just live in it. As a legacy piece of code, I can just take this code and start using it in my application. Sometimes a house might need more rework than you expect. And so it might be that you have to paint it, you have to rewire it, that you have to fix the plumbing. And then you still do have a good house that you can use. But sometimes, you get this.
It’s a money pit, it’s a black hole. You work on it, you work on it, you work on it, you work on it. And the more you work on it, the more problems you find. You going to paint the walls, the paint doesn’t stick. Because the dry wall is damp. You peel the dry wall off and there’s mold. You peel the rest of the dry wall off and you find out it’s moldy because the pipes are leaking. You go to fix the pipes, and you blow out more pipes elsewhere in the system because the pressure is too high. And it goes on and on and on.
And sometimes code is like that. Sometimes we need to look at the code and step back and say, is this code really worth the cost to me? Is this something that I should be fixing? Is it something I should be using? Is it something that I should run away from? Is it completely useless waste of time to me?
So legacy code is pretty interesting because again, on the one hand, it might be a big pile of cash. It might be a pet with a vet bill. It might be a house I can live in, it might be a house, I could fix her upper. It might be a house that I should more properly bulldoze, tear down and start fresh, or sell it as quick as I can for as little as I can get. Whatever it is, take it and run as fast as possible. And we need to think about legacy code in that way as well.
Again, legacy code, it’s coming from someone who isn’t there anymore probably. They’ve left the organization, they moved on to another project, they’ve retired, they’ve gone to another company. You don’t maybe understand this code as well as they do. It might be overly complicated. It’s old. And as we all know, old code is bad code. When you have ever touched your own old code, it’s bad. When you’ve touched someone else’s old code, it’s worse.
So just a thought. Think about what your legacy code is. Think hard when you encounter legacy about the value, especially if you’re spending time on it. If you’re fixing and fixing and fixing stop and ask yourself, is it time to refactor? Or even tear down and replace. Now we have a truck coming by, we’ll wait for the truck. It’s nice and loud. Thank you. Thank you. That’s nice.
Okay, so think hard. If this code needs to be completely rebuilt, is it worth the cost? If it’s breaking all the time? Is it worth the effort? Is it better to tear it down and start over? Or is it a beautiful old mansion that could be on the national registry? And it’s worth the repair? Is this a bird that’s a great companion? And even though there’s that bills, it’ll be your friend for the rest of your life when everyone else has forsaken you and because you’re so obsessed with writing code.
So let me know what you think. Put it down in the comments. What kind of legacy code have you encountered? Don’t forget, if you liked the video, thumbs up and subscribe so you keep track of all the new videos.