It’s a compromise between structural and nominal typing to boost code reuse without locking yourself prematurely into structural typing. It’s been tried before and has been given different names.
Personally I’m fond of it. It’s one of several ways to blur the line between “is a” and “has a” relationships. We used to go out of our way to distinguish the two (eg in UML) but it has fallen out of favor.
A coworker long ago convinced me that improvements to delegation would be coming soon to new languages and unfortunately this is one of the first times I’ve seen it happen close to the way he hoped.
Kotlin and Groovy are two languages where you get direct support for delegation.
Delegation is extremely powerful, but it is easily implementable in most OO and Functional languages, no?
If you have to implement it by hand you end up not doing it, especially in languages where "extends" is right there.
What do you mean by delegation?
Was about to comment in a similar fashion. One more example of a language who has embraced this: Clojure
Protocols, polymorphism, dynamic dispatch (i.e. multi-methods) and immutability baked in.
It's fun, but it's frustrating as well. Haskell had this stuff 20 years ago, but wasn't able to convey how valuable it was to most people.
Swift specifically took these ideas from Haskell, Haskell was even mentioned in comments in Swift source code for a time.
Re:Value-Oriented Programming
by AstralStorm on Friday August 31, 2018 @12:59PM
(#17887116)
Obviously then keep the specification, preferably testable, formal and verifiable of the protocol.
Without this part, you end up with a real big mess similar to 90s internet.
It is fun to see how the benefits of immutability, typeclasses, and (sort of) ADTs / pattern matching are being discovered independently.