This is a good reason to have decent, intent revealing tests. Even if the code descends into a ball of mud, you still have the tests characterizing what the function of the system ought to be, allowing a rewrite with more than just blind faith and seat of your pants optimism.
Then again, code bases with suites of extensive tests probably tend to not be the real worst cases. But if they are, at least you have the tools to do lots of iterative/evolutionary refactoring. It's amazing the radical transformations that crappy code can go through when you gain confidence from good tests.
Having done huge multi-year refactoring efforts in both scenarios, I know which one I'd prefer.
Then again, code bases with suites of extensive tests probably tend to not be the real worst cases. But if they are, at least you have the tools to do lots of iterative/evolutionary refactoring. It's amazing the radical transformations that crappy code can go through when you gain confidence from good tests.
Having done huge multi-year refactoring efforts in both scenarios, I know which one I'd prefer.