Thoroughly field-tested code with all the weird exceptions, edge cases, and other discovered requirements covered: "This code is so complicated! It's not even worth refactoring, so let's just scrap it and start over."
Rewritten code: "It used to frobnicate instead of mogrifying when you click the 'download' button after sorting the table by reverse priority order during a month with two full moons. The customer needed that functionality yesterday, get it fixed and pushed to prod ASAP."
Several top-priority bug-fixes and tens of thousands of man-hours later: All the weird edge cases, exceptions, and unspoken requirements have been rediscovered and implemented. Go to 1.
Occasionally you can genuinely find abstractions which make expressing and maintaining those requirements easier. Designing a high-quality rule system can be difficult, but often well-worth it, imo
It is not. I've done it. Once you understand the complicated mess (often a big ball of mud or spaghetti code) you can identify the edge cases.
With an understanding of core design patterns, the core logic can be simplified, while edge cases can be moved to independent classes with a strategy pattern, chain of responsibility, adapter, or some other pattern.
Sometimes it can't be done that way, of course, but one usually can better clarify the edge case visibility and group it at the very least.
Edit: automated tests must be built that verify the new version output matches the old output.
656
u/sillybear25 Nov 25 '22
Thoroughly field-tested code with all the weird exceptions, edge cases, and other discovered requirements covered: "This code is so complicated! It's not even worth refactoring, so let's just scrap it and start over."
Rewritten code: "It used to frobnicate instead of mogrifying when you click the 'download' button after sorting the table by reverse priority order during a month with two full moons. The customer needed that functionality yesterday, get it fixed and pushed to prod ASAP."
Several top-priority bug-fixes and tens of thousands of man-hours later: All the weird edge cases, exceptions, and unspoken requirements have been rediscovered and implemented. Go to 1.