DEV Community

Discussion on: How do you deal with legacy projects?

Collapse
 
recursivefaults profile image
Ryan Latta

I love legacy codebases.

First riddle is how did a bunch of smart developers create a codebase like that? Are you doing anything so significantly different that you aren't leaving a legacy yourself?

Ok, now that I've ruined everyone's day lets get into it.

Legacy code is an odd animal because it generally does the job it was asked to do, but is generally hard to understand and harder to change. So, first thing I like to do is respect that this code is doing its job and someone is getting something out of it.

Most legacy codebases suffer from a problem that nobody can keep it in their head or remember what it does or how a feature behaves. Most legacy codebses don't have tests either.

You're writing tests right?

So, all you can do is accept that the code exists the way it needs to even if it looks broken or buggy. Now you need to protect that code from abberant change by writing some tests. These tests don't tell you it works, but they do tell you if its behavior changes. You need that.

With some tests you can now begin to make changes where you surgically adjust functionality while cleaning up as you go. The tests inform you that behavior is maintained as you work.

Last bit is the temptation to rewrite or start a new project. Rewrites are a disaster waiting to happen. Remember that depressing thing I said earlier? Compound that with the fact that nobody knows what this thing does and you have a recipe for a instant legacy codebase that fails to do what the other one does too.

You can implement several isolation patterns in place like the branch by abstraction or strangler to slowly but surely create a modern implementation of it. But before anyone tries this, they had better be serious about working in a significantly different way or they'll make it worse.

Collapse
 
kant312 profile image
Quentin Delcourt

"Most legacy codebases suffer from a problem that nobody can keep it in their head or remember what it does or how a feature behaves." 👉 That is so true 😅