Table of Contents
    Home / Definitions / Legacy Code
    Development 2 min read

    Legacy code refers to source code that has been inherited from a previous version of a website or software application. Developers often regard legacy code with some disdain because it is thought of as less reliable than state-of-the-art new code. This comes from an assumption that the previous developer who wrote the code was less skilled or could have done a better job, but the reality is that legacy code is usually reflective of the constraints and parameters in place when it was written. Therefore, legacy code should not be expected to work seamlessly with all future updates. This also means all new code will become legacy code at some point.

    How to use legacy code

    While not all legacy code is inherently bad, there are steps programmers should take to review and revise legacy code so it can maintain its integrity.

    • Read the documentation. Keep on hand the documentation that accompanies the legacy code. This will help you make sense of all the moving parts so you can understand what impact one piece of code has on the broader system.
    • Run legacy tests. Create and perform tests on the legacy code so you can identify all of the problem areas. This includes unit tests and characterization tests.
    • Try refactoring. Refactoring involves simplifying the internal code structure to prevent software entropy. This eliminates potential weaknesses and minimizes the amount of changes needed, but it should be done in small doses to avoid any major disruption.
    • Make changes incrementally. Similar to the process of refactoring, any changes to the function of the code should be documented and implemented gradually so that each modification can be tested and reviewed individually. Otherwise, you could end up with a broken system and no idea what’s causing the malfunction.

    Related links: