What a boring trite reply. All of this is analogous to badly written spaghetti code. And yes, you can absolutely avoid all of this if you know what you're doing.
Not trite at all. Bad code and bad architectures are a reality. You can fix them in theory, but that takes a lot of time and needs to be done incrementally. In the meantime, you have to live with the problem at hand.