DEV Community

Cover image for Thoughts on Legacy Code
Lucas Pacheco
Lucas Pacheco

Posted on

Thoughts on Legacy Code

Behold, you get your first job as a developer, excited to work on new technologies, the ones you looked at on YouTube videos, on Twitter trending topics, on blog posts, and on many other websites. Then, in the first months of work, you receive the following dose of reality: maintenance of a legacy code. Whoever has never had to keep a legacy code, can be sure that one day it will!

Recently, I had to carry out some maintenance, and, believe me, adding new features to legacy systems. This prompted a question in me about the need to maintain legacy software and how to perform this maintenance. In addition, how we should develop our current codes to be maintained in the future.

Knowing your application

Before start running the code, try to understand:

  • What does this application accomplish?
  • How important is this application for the company?
  • What are the affected areas?
  • What is the purpose of your change?

I believe that making any changes to the code, before having answers to these questions, can be very dangerous for the business, because you simply do not know the possible impacts. Have you ever imagined a login service down because you didn't know there was a dependency? In addition, the time it takes you to develop something you don't fully understand is much longer than the time it took if you had studied the application before.

Application refactoring

It is very common during the analysis of the old code to see that thought: "What did you do here? Why did you do it like this? This is very wrong!". Before judging someone else's code, remember: you don't know the circumstances under which this application was developed and you yourself have certainly written very similar code that you are seeing. At this point, you have the opportunity to improve this part of the code, and when possible, this should certainly be done, as you will hardly be the last to touch this application. There are several refactoring techniques and several books, so if you want to go deeper into the subject, I recommend reading one of these specialized books on the subject.

Tests

At this point, you may think, "There are no tests on the project! This technology is very old!" Again, here is the opportunity for you to accomplish them. Nowadays, delivering any application without testing in production must be well thought out and justified. Of course, there may be some very old technologies that performing unit tests or other tests are more complicated or even impossible to perform. For these cases, it will be necessary to perform very good validation with functional tests. Whenever possible, look for the person in charge of the business area to validate these changes.

What should I do with my current applications?

First, reliable documentation can make future application maintenance much easier. It can be a board in JIRA, some User Stories, a document with functional requirements, any information you may have about what is being developed. But the most important thing is to make this information accessible. It is useless to document everything and keep it on your computer.

What environment settings are needed to run and develop your application? In one of my last projects, I had to perform maintenance on a system that only ran on Windows XP! Imagine how it was to get an XP machine in 2020 to develop. In addition, by knowing what resources are needed to start the application, a lot of time can be saved with execution errors.

Develop tests for your applications! They will certainly assist you during the current development and will assist you when you need to change it in the future. In addition to ensuring that your future changes will not break the code that has been in production for years.

When developing your current system, you can be sure that it will be bequeathed one day and you or someone will have to work on it in the future. So always think about it while working with your super-cool technology and writing code.

Today's hype is tomorrow's legacy!

Thanks for your time! Comment below any tips or doubts.

Top comments (2)

Collapse
 
montedodev profile image
Rafael Montedo

Sometimes we need to link new applications to our legacy systems, a solution to do that is using middlewares =)

Collapse
 
lucaspsilveira profile image
Lucas Pacheco

That's true. In time our application will use those middlewares and the changes in the legacy system will begin to diminish