When I first started as a software engineer in my first professional job. We cater different applications designed using .NET, Python and PHP. And one of the big task for me at that time is handling a legacy system.

Different organization and companies have different definition of legacy code/system. In our organization, a legacy system is old, ugly and difficult to maintain. No tests, unusable comments, no documentations, or whatsover, if there’s any, it’s of no use.

I handled multiple desktop and web applications that are built on .NET 2.0 WebForms with spaghetti code all over. And a Python web application that has no framework. In fairness to the Python web that I handled, it is stable, almost no issues and no incidents being called to us regarding this app. And as an inside joke to our organization, we don’t touch this magic.

As a fresh dev at that time, this is a big challenge to me, working with unfamiliar code base. I always think that the code is bad, I could have done better. But as I grew as a developer, I realized that legacy codes/systems are there for a reason, they have their own advantages and disadvantages. It may have been written 8-15 years ago and its still working as intended. One of the reason why it is old and still being use is because of only reason: that it gets the job done.

Here are the top 3 things I learned working with legacy systems

Not understanding what it does doesn’t mean its bad code

I was a victim of the “Let’s build everything from scratch” solution during my early years as developer. But it turns out that this legacy system that I was replacing is properly written. Good structure and easy to maintain once you got the hang of it. Unfamiliarity of the code is not equal to bad code. As a developer we all have different styles and techniques. When you see a function or method that you might think needs to be refactor, try to see first why the previous developer did it.

Be Patient

Working with a legacy system can be stressful if you don’t handle it correctly. Think of it as a learning curve that if you survive this stage you can handle any projects that you may encounter. In my opinion, working with legacy system will improve your troubleshooting or debugging skills. I assure you, this will teach you a lot of things that will be helpful to your career’s future.

Refactor cautiously

Create unit tests, then do your changes. You might see some codes, functions and methods that you might think can be improve or enhance, you can refactor those if you think its for the good of the system. But do it cautiously. You must create unit tests before you refactor the working codes.

Additional Refactoring tips

One technique or method that I use when refactoring is called Sprout Refactoring.

  1. You create your code on a separate place.
  2. Unit test this new code.
  3. Reproduce/Replicate the calling of this new code.
  4. And finally, call the new code from the legacy system.

Happy Refactoring!