How to Work Effectively with Legacy Code?

By CIOReview | Friday, March 31, 2017

At some point in developer’s carrier, there might be times when they have to deal with legacy codes—a program written by unknown person. Working with these legacy codes can be challenging, due its enigmatic structure and unfamiliar language used by unknown programmers. As this legacy software application carries enormous amount of latent defects, developers have to spend most of their time fixing bugs and struggling with fragile code rather than building new features. With all these challenges around, one question that remains in every developers mind is “how to overcome these challenges associated with legacy codes?”

One of the ways to address this issue is by refactoring components over time, but developers are often reluctant with this approach because of the fear of breaking the existing functionality. Refactoring is essential for applications code, as new features and bug fixes are related to existing functionality. Without refactoring, the original design loses its simplicity. The biggest pain point in refactoring is the lack of tests that differentiate the existing behavior of a component and verifying its correctness.

This is a growing issue and it gets complicated when the legacy code is deployed in a new platform or product. The lack of test artifacts leads to increase in latent defects and there is a massive quality gap that needs to be filled, but many organization lack knowledge on resources needed to address the problem.

Testing Legacy Application with Baseline Testing

Most of the organization uses Baseline testing, also known as characterization, for legacy code bases that have inadequate test cases. As legacy application has been leveraged for some time, developers can use the existing codes as the basis to build test scenarios instead of building all of the test cases from scratch. Once this baseline testing has been done to differentiate or characterize the behavior of the software, complete regression suite present can be executed on a daily basis to ensure that updates and alterations to the code won’t hamper the existing functionality.

Further, to automate the integration and testing process, developers can capitalize on impact-analysis to execute only the set of test cases required to show the impact of code changes on the integrity of the whole system. With the help of change-based testing, developers can make modifications and get feedback on its impact to the entire application within a short period of time. As a result, this approach allows developers to make quick incremental changes on the code knowing that they have the test cases required to capture the existing behavior of the software.

Comprehending legacy code

The legacy application is usually developed using the low-level data access technology. In such scenario, new repository method will be returning the same type of object that the original code was using—a unique row-set and not a business object. Creating a new business object repository instead of refactoring will help in making the process more manageable.

If developers are working with a combination of older and new technology in the application, such as ASP Classic and ASP.NET, they can try incorporating innovative repository into a Component Object Model technology. This way developer can maintain a single code line for all database access and overcome the challenges of legacy codes.