Should it be saved?
I recently got an object lesson (pun intended) in when to start over on something. When a deadline rears its ugly head, that’s usually the best time in the project to “slow down to hurry up.” The more pressured and frazzled you get, the more mistakes you make. The more you keep thinking “just this one last fix (and this slightly wonky design will work).” Easier said than done.
The past two weeks of my work life have been invested in debugging something that was “99% done” pretty much the whole time. But after this huge waste of time, this area of the product was ultimately redesigned and rewritten in two days and now has no significant bugs. This kind of “we’re almost there” failure mode reminds me of mistakes people make in the stock market trying to “wait out” bad investments. Just because the stock you bought is going down, doesn’t mean you shouldn’t sell it.
In this particular “bad investment,” the trouble was that the underlying model was wrong. And the reason it was wrong was because our original conception of the problem was wrong. And the reason that was wrong was that we rushed at the start of the project to start coding when we didn’t really have the requirements down as fully as we thought we did. Under deadline pressure, who wants to go back and re-examine the foundations of your model when it’s almost working? Sound familiar?
Our particular issue stemmed from thinking that certain concepts were related when they weren’t related enough. This can be a really tricky thing in OO programming because it can initially look like like B extends A and C extends A is a good model, simply because B and C have some things in common. But in some cases this can be a trap where you slowly discover that they aren’t really the same concept. And unfortunately, in the meantime, you’ve wrecked a good chunk of your codebase (well, at least polluted it with a lot of unnecessary code).
I’m curious if any readers out there have ideas about how to identify when code should be saved and “remodeled” and when it should be leveled and rebuilt from the ground up. How do you know when to “cut and run?”
I’m also curious if people have interesting ideas about how to identify inheritance schemes that have run amok. Do you also find that too much adherence to DRY sometimes leads to unnecessary or unwise inheritance?