Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advice on working with legacy code

I need some advice on how to work with legacy code.

A while ago, I was given the task to add a few reports to a reporting app. written in Struts 1, back in 2005. No big deal, but the code is quite messy. No usage of Action forms, and basically the code is one huge action, and a lot of if-else statements inside. Also, no one here has functional knowledge on this. We just happened to have it in our contract.

I'm quite unhappy about this, and not sure how to proceed. This application is invisible: Few people (but all very important) use it, so they don't care whether my eyes bleed while reading the code, standards, etc.

However, I feel that a technical debt is to be paid. How should I proceed on this? Continue down the if-else road, or try to do this requirement the right way, ignoring the rest of the project? Starting a huge refactor, risking my deadline?

like image 473
Tom Avatar asked Jan 21 '11 14:01

Tom


People also ask

How does something become legacy code?

Legacy code is old computer source code. It could simply refer to an organization's existing code base which has been written over many years, or it could imply a codebase that is in some respect obsolete or supporting something obsolete.

What is refactoring legacy code?

Refactoring legacy code is the process of improving the structure of an old or unfamiliar code without changing its functionality. The idea is to clean up lines of complex codes so you can understand or work with them better. This may include reducing redundancies or errors to make the code readable and manageable.


1 Answers

Legacy code is a big issue, and I'm sure people will not agree!

I would say that starting a big re-factor could be a mistake.

A big re-factor means doing a lot of work to make it function exactly the way that it does now. If you choose to take this on on your own, there won't be a lot of visibility of what you are doing. If it works, no one will know the hours of work you put it. If it does NOT work, and you end up with tidy code, but add some bugs (and who has ever written code without adding some bugs) then you will get 'why did this change' type questions.

I have currently nearly completed a project working on a 10 year old code base. We have done quite a few bits of re-factoring along the way. But for each re-factor we have made we can justify 'this specific change will make the actual task we are doing now easier'. Rather than 'this is now cleaner for future work'. We have found that as we worked on the code, fixing the issues that we actually come up against one at a time, we have cleaned up a lot of it, without breaking it (much).

And I would say before you can re-factor much, you will need automated tests, so you can be fairly happy that you have put it back together right!

Most re-factoring is done to 'make maintenance and future development easier'. Your project sounds like there is not a lot of future development coming. That limits the advantage a re-factor will give the company.

like image 113
Jon Avatar answered Nov 13 '22 21:11

Jon