Hacker News new | past | comments | ask | show | jobs | submit login

My thing is I go simple. I'm good, maybe messy. Finally see enough / think I know a good abstraction and pull the trigger and later I find out ... oh man I was wrong. Knowing when you know is the hard part.

I've got some abstractions out there I wrote early on when I didn't think I coded well and they have lived for years and saved tons of time.

Others don't live long :(




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).


The 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.


> 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.


The 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.


All 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.


I 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.


Ah 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.


If 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.


It 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.


Not-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).


>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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: