The heart of a piece of software is its source code. Whether the program works the way it is supposed to and which functions can be performed depends on in­struc­tions and commands contained in this code. Pro­gram­mers regularly edit, maintain, and update this code to optimise its usability. Any changes made to the code may result in software errors or affect the program’s func­tion­al­ity.

Main­tain­ing and updating software is always par­tic­u­larly prob­lem­at­ic for de­velopers and pro­gram­mers when they have to work with code that they did not write them­selves or that was written for older operating systems that are no longer supported in equally old versions of the un­der­ly­ing pro­gram­ming language. Here you will learn exactly what legacy code is and how to best handle it.

Defin­i­tion of legacy code

The term “legacy code” is used in the field of software tech­no­logy. This term refers to old code that is usually no longer in active de­vel­op­ment. In a sense, legacy code is the an­ti­thes­is of clean code which is easy to un­der­stand, maintain, and adapt. Legacy code is unwieldy, outdated, and messy, which can lead to numerous problems. The exact meaning of the term greatly depends on the developer’s per­spect­ive and current situation. However, in general, legacy code is char­ac­ter­ised by the following aspects:

  • The code is no longer being main­tained by the original developer
  • The code was ori­gin­ally written for operating systems that are no longer supported
  • You cannot use automated tests to find bugs in this code

What are the dis­ad­vant­ages of legacy code?

Why is legacy code used at all if it has so many dis­ad­vant­ages? Well, it simply cannot always be avoided. Often, over the course of a project, a new pro­gram­mer will take over the main­ten­ance and further de­vel­op­ment of the code. While the original developer usually has an intuitive un­der­stand­ing of the code, new team members will have to develop that same un­der­stand­ing. Sometimes parts of the code are over­looked or not fully un­der­stood.

If a piece of code is main­tained, updated, and edited by numerous different pro­gram­mers over many years, that code can become a patchwork quilt as time goes on that is in­creas­ingly difficult to un­der­stand and modify. The problem is that, at some point, it will become im­possible to make any required updates or modi­fic­a­tions to the code as no one will un­der­stand it or its func­tion­al­ity.

Another dis­ad­vant­age of legacy code is that you cannot perform re­gres­sion testing (automated tests) on it because its pro­gram­ming is too bulky, unwieldy, and patchy. That’s why de­velopers dealing with legacy code have to perform a sig­ni­fic­antly greater amount of manual testing. It is more difficult to fix bugs and more com­plic­ated to implement updates.

Re­fact­or­ing: the right solution for legacy code

Legacy code is something that de­velopers are reluctant to deal with for a variety of reasons. One of the biggest issues is that you cannot use automated tests to check the code for bugs or errors. So, what can de­velopers do if they suddenly find them­selves con­fron­ted with legacy code when working on a new project?

The best solution is probably re­fact­or­ing the code. In this de­vel­op­ment process, code is re­struc­tured without changing its original function. However, before the actual re­struc­tur­ing can happen, the pro­gram­mers must first un­der­stand what each part of the code is re­spons­ible for. In addition, tests must be performed to check all the functions.

They can only begin the actual re­fact­or­ing once it is clear how the code works. The code is then optimised piece by piece. Any un­ne­ces­sary code is removed or rewritten. Classes and variables in the code are sim­pli­fied and merged. Command methods are adapted and rewritten. In the end, re­fact­or­ing is basically a general overhaul of the legacy code. The resulting code is easier to un­der­stand, maintain, and adapt.

Go to Main Menu