Legacy Code Should Be Respected, Not Hated
Developers hate legacy code. It’s dirty, it’s crowded, it’s ugly, it’s messy, it’s… old. But we shouldn’t have a negative outlook on legacy or old code. It’s there for a reason, we just need to appreciate that reason.
When starting a new job and getting your first look at the legacy codebase, it’s easy to be frightened or disgusted. If the code has been around for a long time (in Internet years), it probably doesn’t meet modern style guides or follow modern practices. We can easily look at this code and deem it inferior to the code that is being written presently. To do so, though, is to disrespect the developers and the decisions that came before us.
We need to reframe our minds and stop hating and disrespecting legacy code and instead appreciate it for what it is: legacy code is established. The lines you’re judging are there for a reason; they have lasted the test of time; they have served a purpose. Most importantly of all, they have given you a job. Without those “old” or “ugly” lines of code, you would not have the job that you’re using now to put down that very code.
Programmers don’t set out with the intention of writing bad or ugly code. They don’t sit down and think of the most convoluted solution they can write. Code becomes complex, intertwined, and unpleasant over time. Each feature begins with a single typed character and builds from there. As the business grows and its needs change, so does the code.
A friend of mine once said that “bad” code is the product of not enough time, poorly defined requirements, or inexperience, not necessarily a bad programmer. Business moves fast and as developers, we’re constantly working against the clock to release features to draw in customers and make more money. It’s for these reasons that we must change how we think about and see legacy code – it is not something to be looked down upon, it is a legacy that was passed down to us that we must now carry forward for the next generation of programmers. When we are handed a legacy codebase, it becomes ours to shepherd forward.
Build and improve upon the legacy, but overall, respect it.