You can get rid of poor maintenance of the code base when you are a very small (less than 10-20 people or so in one project) development team. If your project grows and your team grows, either your practices will increase, or you will fail.
The change you are asking for is the transition from hacking to programming, and finally, Software Engineering.
With Software Engineering, you learn that not everyone on the team is perfect. You look at the code, you guarantee that others test, you cross-check each other.
You begin to see the need for an architect who can digest the wishes of clients and translate them into a project document. It can easily be eaten in a month before anyone else is added to the project (but months or even years can be saved during development time!). He is sure that everything makes sense and will fit well.
You have project documents, usually UML, so different parts of the team can understand the integration points. You acknowledge that everything that has been done, you may have to redo it without the people who did it, so you document it.
Your quality process becomes much more stringent, and they begin to apply the rules as you check for changes that address specific errors during testing.
Testing, refactoring, etc., are obviously key, and their re-application is carried out by an expert review and team.
I'm not saying that this type of material is always necessary, obviously it is not, but in your question you are discussing the basics of cruel code, and these good practices are often the solution to this problem.
Usually, these good practices are implemented after the GIANT project, which fails completely because the code base is so bad. Then they fire all those who cannot shy away from guilt, hire some managers who hopefully have some experience working with larger projects and (if they don't have money) restart from scratch.
At least my experience. Ymmv