Strategies For Untangling Legacy Code

Tips to improve your understanding of legacy codebases in less time

Saeed Ahmad
Oct 10 · 4 min read

As software engineers, we are always busy making innovative things using different languages and frameworks. Sometimes we are expected to do that through initiating a new project but most of the time we are working on a legacy codebase that was initially written by someone else.

Recently, some researchers have proposed methods to automate the refactoring and related operations in a legacy codebase. In this article, we will be looking into how to deal with legacy codebases manually.

When we are working on legacy systems, we are not always familiar with what’s going on inside them. Every person has a different code-writing style. Also, if the codebase is a few years older, it might be following more traditional software patterns that are no longer used that way.

All in all, there are a lot of challenges when you are working on a legacy codebase. Below, we will be outlining some of the points that you need to keep in mind while working on such codebases.

1. Figure Out the Structure

Image for post
Image for post
MVC software design pattern

There might be some patterns that your legacy codebase follows or maybe a certain pattern that has been implemented in it. A good understanding of the architecture helps you when you’re just starting to work on a legacy codebase.

As you know there are some software design patterns that are usually followed while writing code. Common ones are MVC, MVVC, MVT, and others.

If you want to understand a codebase better, then it’s worth investing some time to figure out the software design pattern followed in the codebase and learn more about it.

2. Use a Debugger

Image for post
Image for post
Rookout Sandbox

There are various tools that can help you understand the codebase faster. When new developers start working on something, they need to log data or put identifiers in different classes or modules to understand the flow of the codebase.

Software engineers also need to create scenarios on their local machines to investigate any problems that occurred in the live code. If someone’s new to the codebase, then that’s an even bigger challenge.

This is the point where tools like Rookout, Visual Studio Code, or IntelliJ IDEA can help you debug your codebase without putting too much focus and effort on configurational things. The integration of Rookout is quite seamless, for example, and can help you speed up your workflow.

What you need to do is integrate an SDK into your live application. When you are done with that, add breakpoints throughout your application and collect any information that you need from it.

The main advantage of a debugger like Rookout is that you just need to add a line to logging and it can cover almost everything. Be it some stack trace, local or global variable, or any other metric that you might need, the tool has it covered.

3. Check the Obvious

Image for post
Image for post
A typical structure of a React Native codebase — You can start reading the code from actions

If you are familiar with a programming language or framework that was used to develop a particular codebase, then there are some things that you are able to understand right off the bat.

You can then start from those modules, classes, or parts that are easier for you to understand and then solidify your learning based on that. Choose the easiest modules or parts and then start working on them.

4. Explore Flow in the Codebase

Image for post
Image for post
Typical authentication flow in a web codebase — You can start with auth flow to understand the codebase [Source]

Web apps and codebases are usually based on certain flows. If it’s a backend system, it may consist of different APIs like login, register, and other APIs related to different CRUD operations.

In the frontend systems, we also have similar flows that use APIs to perform certain operations.

To get a good idea of how your codebase works, you need to pick up a certain module of APIs or a flow and then run it on your local machine to see how it works.

5. Take Your Time

When you are new to a codebase, you always need some time to properly understand what’s going on inside it. Sometimes, software engineers start ‘fixing’ things right away without properly going through the codebase. It’s not really a surprise that this approach often results in breaking things that are already working.

It’s always important to go through a codebase properly and understand it. This initial time investment can save you from wasting any in the future. If you are able to understand the architecture, design pattern, and general flow of the codebase, it makes it a lot easier to address problems and make changes or improvements later on.


In a nutshell, if you are able to follow some of the practices about how to untangle legacy code, then you’ll be able to quickly understand it.

Debugging, logging, and testing are essential parts of this process. So, don’t forget to use them while you are working on a legacy codebase. Make sure to check them out so that you are able to work seamlessly on any codebase given to you.

JavaScript In Plain English

New JavaScript + Web Development articles every day.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store