That's why it's very important to work for an organization run by engineers or former engineers when writing software.
And engineers who actually shipped and maintained successful products over time.
For software developed in-house by non-software organizations, the incentives are all wrong because management cannot properly assess the value of well architected systems.