4 ms·
Removing duplication != abstraction. Many copy & paste scenarios can be avoided without creating any meaningful abstraction. Generally this is best done with a
by gregwebs 8y ago
Removing duplication != abstraction.
Many copy & paste scenarios can be avoided without creating any meaningful abstraction. Generally this is best done with a stateless (pure) function that has few if any conditionals and does not involve design patterns such as inheritance, overriding, or even creating new compositions. It should feel easy and boring when you are doing this.
Abstraction is a new representation that calls for deep thought and I agree is easy to mess up.
The need for DRY also depends on type-safety. Type-safe boilerplate generally adds verbosity, but few bugs. This article is coming from the Ruby world where a bug lurks behind every untested line of code: this can create a lot of pressure to make boilerplate free code which can end up turning into abstractions. But every code change (without code coverage) in dynamic languages is also an enormous risk. In type-safe languages the compiler can help ensure that the process of removing duplication is correct.
- machinelearning 8y agoThis is why the article says "wrong" abstraction. Replacing duplication with abstraction often leads to the wrong abstraction. That's the point of the article. That being said, good thoughts on solving duplication correctly.
- hinkley 8y agoConversationally I would say that calling a sequence of functions was composing them. I’m pretty sure you’re talking about composition in terms of heavy weight enterprisey terms but I think that is a pretty fine line.
- alexandercrohde 8y agoI agree. I suspect the author is coming from a purely-oop background, where making a subclass/trait is a very costly and clumsy way to reuse logic. In a functional paradigm, even the most trivial of abstraction pays off handsomely. This is exactly what "map" is for example.
- spion 8y agoTrivial doesn't mean it wasn't well thought out. On the contrary the more trivial the abstraction the more likely its more general, since it has less constraints.