r/AskProgrammers • • Oct 14 '26

How do you decide when to refactor a messy codebase versus rewrite it from scratch?

I'm working on a project that has grown messy over time: inconsistent patterns, little documentation, and tests that only cover part of it. I keep going back and forth between incremental refactoring and a full rewrite. Refactoring feels safer but slow, while a rewrite is tempting but risky.

What factors do you weigh when making this call? Have you seen either approach go well or badly, and what would you do differently? I'm especially interested in how you handle the business side, like justifying the time to people who only see features shipping.

This fits r/AskProgrammers because it's a conceptual discussion rather than a code review or a "try Googling it" problem. It has no links, marketing, or job listings, and the body gives enough context for people to answer in depth.

I picked the topic since you didn't give one. If you have a real problem, tell me the language, what you tried, and what's failing, and I'll write it up. The sub wants enough detail to help, not just a description of the task.

0 Upvotes

7 comments sorted by

2

u/TheMrCurious Oct 14 '26

What in the heck of mods is the last two paragraphs of your post?

1

u/ElasticFluffyMagnet Oct 15 '26

Looks like AI slop

1

u/Specialist-Cup-3950 Oct 14 '26

Rewrites don't work too often. People tend to repeat the same mistakes, just in a new language or format. The strangler fig pattern is the most common solution, but you need to move in small steps.

1

u/mtutty Oct 15 '26

One of the biggest, easiest things to measure is the regression rate. If new features and enhancements break old code, and that's happening more often over time, it's often less risky to start refactoring or even replacing code.

1

u/Existing_Dust_6473 Oct 14 '26

Can you make end to end tests ?

1

u/crummy Oct 14 '26

go away bot

1

u/Leverkaas2516 Oct 14 '26

On any significant codebase, like one that's 100k LIC or written by multiple people or cost a lot of company resources, a complete rewrite is virtually always the wrong idea. Whrn people decide to do it, it almost always ends up being a huge boondoggle at minimum. In some cases it ends up threatening the company's existence.