I’m pretty much sure that sooner or later every developer finds themselves working on a project that makes them face the need to refactor legacy code. For those lucky ones who didn’t experience it firsthand—legacy code is code with a past. It’s code that someone else wrote and you inherit it for further work. But unlike your family inheritance, legacy code that needs refactoring is not exactly something to look forward to. Why?

First of all, this legacy code was passed multiple times from one developer’s hands into another’s, meaning there might be some chaos and incoherence involved (and usually is). The application core or even business concept itself may have changed substantially over the years. More often than not, your predecessors didn’t have enough time for proper maintenance, like keeping documentation up-to-date, refactoring, or simply stopping for a while to analyze the technology debt the project may have been accruing.

In our case, one such moment of truth happened almost a year ago, back when we were working on an HR Web app. First commits date back to the year 2015. Early on, the application was supposed to be rather small and maintained only by the product owner. And that’s very often the case—apps start out small and then get bigger and bigger as the team grows. If you don’t pay attention, your code might get very messy, very quickly. And that’s exactly what happened there.

In a situation like this, everyone has to decide whether to build a new version of the app from scratch or refactor it. We went with refactoring because it’s our preferred approach. As the topic is a bit touchy, especially for your client, you want to be well-prepared ahead of time, believe me on that.

We learned our lesson on working effectively with legacy code and I decided to share our story. Best case scenario, we’ll save you some time thinking about the right solution, help you avoid some mistakes, and maybe even convince you to give refactoring a shot if you’re not exactly a believer. Worst case scenario? Well, you’ll definitely have some fun reading about how we were thrown into the abyss and slowly clawed our way back out into the light.

#javascript #business #development #ruby/rails #legacy code

Working Effectively With Legacy Code — How To Cooperate With A Client When Refactoring
1.55 GEEK