2 ms·
In my experience the worst messes I’ve had to deal with are cases where people didn’t DRY enough: it’s easy to “unDRY” a function: you just duplicate it and ren
by fiddlerwoaroof 8y ago
In my experience the worst messes I’ve had to deal with are cases where people didn’t DRY enough: it’s easy to “unDRY” a function: you just duplicate it and rename it when you notice that its code serves two different purposes. It’s harder to take duplicate code and deduplicate it, because you have to think really hard about the context and whether or not you’ve encapsulated the environment correctly.
- Aardappel 8y agoThat really depends. A single function is often easy to unDRY, but some abstractions, in particular when stateful objects, hierarchies or layering come into play, are incredibly hard to unDRY. Even just spotting that they can be unDRIED without side effects can be super hard, making it such that most people won't have the courage to do it. Now you are much more stuck with this code than any repeating code. I'd claim that _on average_ DRY-ing is easier than unDRY-ing. This assumes the repeating code is intentionally kept simple and linear. The absolute worst code is a mix of repeating code and half-assed abstractions, where the "perfect refactoring" would have to "move" or "redo" abstractions. This to me is even harder than DRY or unDRY.