DEV Community

Cover image for Working Effectively With Legacy Code

Working Effectively With Legacy Code

Christopher Glikpo
A learner and a Youtuber who likes to write Technical Blog.
・2 min read

What Is Legacy Code?

Legacy code is source code inherited from someone else or inherited from an older version of the software. It can also be any code that you don’t understand and that’s difficult to change.

Working with Legacy Code

When starting work on an existing project, the most common error novices make is attempting to understand the entire system before attempting to make modifications. Big error; at that rate, you'll take a long time, if ever, to have a major influence on the project. You must overcome your initial codeblindness, and the only way to do so is to get your hands dirty.Hands down, the best way to learn a codebase is by changing it.

Here's a bit of advice that can help you get started making substantial modifications to almost any current codebase: Everything has an entrypoint. That might be a GET endpoint on a server. That might be a click handler in an SPA. That may be an exposed method for a module. If you start from the beginning, you may literally "follow the rabbit down the rabbit hole.".Once you find the entrypoint and get to the code in question, it’s just a matter of being able to read that particular piece of code to ascertain what needs to change.

This is why microservices and modular programming are so tempting. The logic stays near to the entrypoints on the surface, which are usually well-defined (after all, what good is a module you can't call?). In a way, you're "closer" to the code since you're not digging through layers and layers of cruft to get what you need.

Having said that, if you have any say in the tasks you take on, I would start with the ones that have clearly demarcated, easily found rabbit holes that don't go too deep (e.g., “paginate GET request”, “button click failing”). A good manager/lead with mentoring experience should be able to spot these as learning opportunities for junior developers.

You don’t have to understand everything, just the piece of code you’re working on. Take on small tasks that have clearly defined entrypoints. This way, you’ll gradually and naturally build an understanding of the codebase, and you’ll be working complex issues in no time.

If you've reached this point, thank you very much. I hope that this tutorial has been helpful for you and I'll see you all in the next.

If you like my work, please consider
Buy me a coffee
so that I can bring more projects, more articles for you

If you want to learn more about Web Development don't forget to follow me on Youtube!

Discussion (0)