20221003 - legacy code garbage trucks analogy

an analogy for working with legacy code

I’ve been working on some legacy system as part of my current job and have found out first hand the pain involved, and I was explaining to someone recently what it was like.

Specifically the challenges I found were that there were real limits to the help the IDE could provide, sometimes it just couldn’t trace the code.

So the analogy is this:

Imagine you’re visiting earth from outer space and you’re trying to understand how a city functions and you have a telescope and can zoom in as far as you want on a facet of the city and observe how it works.

so say you look at a house on a street, and see the person get in their car and drive to the shops, then drive back home with stuff in the car, so you think “ok so that’s how they get supplies to their house” and then you also observe some of the people carrying things from their house to their car, drive to the tip, and dump some stuff and drive home so you think “and that must be how they get waste out of their house”.

So to understand those two aspects of city life, we just had to zoom in on some houses and watch the activity of the people.

But then we also see them take garbage from inside their house and leave in wheely bins outside their house, then we don’t see anything else that happens with that, and we see that the wheely bins are just plastic bins, so what happens to the garbage?

And no matter which people we watch we see the same thing and don’t see them ever taking out the contents and driving it to the tip to dump it there, so how does that work?

From observation alone we can’t know that there is this thing called garbage trucks, which on certain days of the week come around and collect the contents of the wheely bins. If we’re focussing on the people, we don’t see them initiate in any way a request for the garbage truck to come around and empty their wheely bins, so we’d have to be lucky enough to be able to be observing a person at the right moment (when they put the wheely bin out to the curb for collection) before we even got a hint that there might be something else at play.

Unless someone told us that there is this garbage collection service that the city runs periodically, it’s completely not obvious that that’s what’s happening just from looking at the people living in the houses.

Sometimes working with legacy code is a bit like that, sometimes searching for usages of a certain function helps, but sometimes the usage is abstracted away in some factory function based off naming conventions and dynamically looked up at runtime, and if that’s the case, the IDE certainly won’t help you trace it!

The other avenues to search is documentation otherwise just asking around.

back