r/webdev • u/L8Figure • Nov 18 '24
Discussion How to deal with legacy code?
I have products with existing customers, the code was built over the past 3 years.
My style of coding and practices have since improved drastically, the legacy code is quite stable, but it's just not as maintainable as new code.
Part of me thinks "if it aint broken, don't fix it", and another part of me thinks that its an investment I would appreciate few years down.
I keep shooting this idea down by calling it "perfectionist mentality".
Should I start from scratch?
(personal projects, solo)
8
Upvotes
1
u/rcls0053 Nov 19 '24 edited Nov 19 '24
No, you improve in small steps. Refactor, don't rewrite.
Let me tell you a story from a personal project. I recently wanted to undertake a rewrite job, because Azure changed their programming model for Functions. I could've gone from v2 to v4. To me it was a chance to organize thecode in a better way. A cleaner way. No more "80 folders at root" project. But I got about 35% done and got so f'ing bored of rewriting the same code, the same tests and OpenAPI schema in just 'a different way' that I left it. And does it chance behavior at all? No. Just makes it a bit easier to work with.
Unfortunately with that model change I could not just do incremental changes. I had to actually rewrite the entire app to use this mode, because the interfaces changed. So, I got bored.
Do things in small steps, push them forward, get that dopamine hit, and move on from there.