Legacy Code

Make your life with legacy code easier

There are multiple definitions of what legacy code is. One way to define legacy code is: Code to which one or more of the following properties applies:

  • The code was written by someone else.
  • The code is hard to change.
  • The code is the opposite of clean code
  • Nobody understands the code

Another way to define legacy code is the definition by Michael C. Feathers. He defines legacy code as “code without tests”.

Regardless of which definition you consider, visual effects pipelines often consist of legacy code, making developing visual effects pipelines not easy. Legacy code is not easy to change. If you don’t have tests, you don’t know when something breaks, and if you don’t understand the code, you don’t know what could break. This is a significant risk to introduce bugs when changing the code.

Cover and Modify

Michael C. Feathers presented a technique to prevent introducing bugs in his book “Working Effectively with Legacy Code”. The technique is called “Cover and Modify”. First, the legacy code is covered with tests. Once it’s fully covered, the code can be changed safely. The tests will fail if a bug is introduced. It might take some time to write the tests, and you might have to refactor the code to make it run in tests. But this will save a lot of time because no new bugs have to be debugged. It’s also an investment because, in the future, changing the code is straightforward. See the Legacy Code Refactoring Example. It demonstrates how real Legacy Code from a Visual Effects Pipeline is covered with tests.


Last modified September 20, 2020