3 ms·
https://sandimetz.com/blog/2016/1/20/the-wrong-abstraction https://sandimetz.com/blog/2016/1/20/the-wrong-abstraction So many times I've taken code that was a
by lamontcg 5y ago
https://sandimetz.com/blog/2016/1/20/the-wrong-abstraction https://sandimetz.com/blog/2016/1/20/the-wrong-abstraction
So many times I've taken code that was a mess because someone tried blindly DRY code for the sake of being DRY and rub abstractions on top of it and I've reverted the code back to being simple copypasta and its become so much more clearer and robust. Then you can look at the result and a simple abstraction may pop out which can reduce enough code duplication that the result is satisfactory (it may require a bit more boilerplate in the subclasses or whatever, but nothing likely to be brittle under future fixes).
- bcrosby95 5y agoThe nice thing about dealing with an overly-DRY codebase is you can unwind the abstractions. But an underly-DRY codebase... good luck. Copypasta tends to accumulate minor differences and figuring out if those minor differences matters can become very time consuming.
- d0mine 5y agoNot-quite right abstraction also can accumulate minor differences where it is forced on use-cases that fit poorly. It is better to under-abstract and keep some duplication than over-complicate and miss. Complexity snicks up on you (it is a time bomb).
- corrral 5y ago> Copypasta tends to accumulate minor differences and figuring out if those minor differences matters can become very time consuming. The DRY version of this is functions/constructors/methods that take a stupid number of parameters, many with unclear purposes.
- skrtskrt 5y agoAll the libraries I love and use the most have tons of parameters but they are really well documented including their parameters' interactions with each other.
- corrral 5y agoI don't mean well-considered and documented libraries, I mean the thing where someone goes to DRY up a codebase and keeps thinking "oh, if I just add a parameter this function can also handle this one-off case over here..." over, and over, and over, until you've got this function with a name that makes it look straightforward but for some reason it wants three strings, two of which should actually be nulled in most cases (and god help you if you fill in a value when you don't need them), an integer for unclear reasons but it's the same value in every call you can find, and half a dozen booleans that you'll have to go read the source to figure out, because some of them do more than the variable name in the signature implies. Good intentions at every step, but a Frankenstein's monster of a function (or entire class, sometimes) in the end It's the DRY equivalent of having 20 slightly-different copypastes all over a codebase.
- skrtskrt 5y agoAh yes :) The Django monolith I worked in for some time was like this - 30, 30, 40 parameters on the methods to handle completing a purchase.
- Jtsummers 5y agoIf it's unclear, then it's poor code or poor documentation or both. Sane developers will provide a way to obtain default or common configurations rather than forcing you to figure out the 100 different tunable options.
- lamontcg 5y agoIt isn't one sane developer. It is the aggregation of a dozen different developers each adding a knob to close a ticket/bug over the course of maybe 10 years.
- lamontcg 5y agoThe DRY version of this is base classes with subclasses that have crazy protected interfaces that violate Liskov all over the place. I'd rather debug code spaghetti by rearranging copypasta to sort out the simple deltas than try to unwind LSP-violating inheritance spaghetti.
- whatshisface 5y ago>Copypasta tends to accumulate minor differences and figuring out if those minor differences matters can become very time consuming. Welcome to the field of genetics.