top | item 34403876

(no title)

ogoparootbbo | 3 years ago

ad-hoc abstraction is the secret sauce that destroys code bases in the long run and makes things horrendously complex. Composition based on mathematics is more likely to survive years of serving as atomic elements than anything based on ad-hoc human intuition

Composition is hard

discuss

order

veddox|3 years ago

Can you elaborate on this, or link to a more detailed description of what you mean?

belmont_sup|3 years ago

I forgot where I read this, but I'll paraphrase: it's easier to work with 10 objects with 1000 applicable functions than with 1000 objects with 10 methods each.

In Haskell or other typed fp languages, you have all these well-recognized and well-used typeclasses and their attached methods, conceptually equivalent to generic interfaces in c#/java. It's easier to adapt new data structures into these interfaces and have all your existing functions immediately work with them.

The "mathematics" part here is that these typeclasses are backed by category theory that prescribes their behaviors.

There are plenty of random readings you can find, so I won't recommend them. Someone's bound to argue with me on what's a better entrypoint.

I do want to note that you don't need to use haskell or an fp language to use these concepts. Example: a complete set of fp data structures in typescript https://gcanti.github.io/fp-ts/modules/. It's just that fp languages make using them much easier because of their type system.

jeffreygoesto|3 years ago

But inheritance is harder, isn't it?

nuc1e0n|3 years ago

The concept of inheritance in programming is an ill conceived one. Better not to use it at all.