A builder came around the other day to fix the shelf under the sink. We had a leaking tap that over time had been dripping down onto the shelf and the boards had ended up in an awful state. From my perspective, we just simply needed to rip it out and put a new one in.
Luckily, the builder was an expert and explained to me what would have to be done. First we would have to cut out the old board. Pipes were running through it and we would have to dismantle all the plumbing first otherwise. The new solution would be designed to slot in around the pipes, making it less coupled going forward. The next problem was that we wouldn't be able to get a replacement straight in. It was a corner cupboard with an L-shaped board, and even with the slot taken out couldn't be manoeuvred in. The kitchen was a kit set and had been built in around the shelf, making it harder to pull parts out and put replacements in.
His solution was simple, though, we have a shelf made of two rectangular parts. These would connect at a seam to form the L-shape. But having two parts rather than one means we need to add extra reinforcing. His experience told him that we needed to add braces to strengthen the connection between the wood. And to ensure the cupboard is still useful, extra wood would be added at the back and side walls to help support each piece. We would keep these thin so they don't encroach on the storage space. A sound solution that avoided a lot of novice mistakes because of his experience and expertise.
When working on legacy software, the process comes across in much the same way. Sometimes we have to swap out parts of a system that are critical to its function, but are so tightly embedded because the system was built around them. Usually, we end up cutting this out to make room for a replacement, but in doing so add more code to support this separation and decoupling. But if we do it right and have the right support from experienced developers and architects, the solution will be simple and hold up to scrutiny. It might even still fulfil the original needs in a more maintainable and flexible way, without too much compromise.