3 ms·
The idea proposed: use protocols and value types. This avoids the problems with subclasses and with mutability (concurrent modification). Enums are also used as
by nine_k 8y ago
The idea proposed: use protocols and value types. This avoids the problems with subclasses and with mutability (concurrent modification). Enums are also used as a controllable way to have different kinds of related objects and use a switch statement to distinguish them.
It is fun to see how the benefits of immutability, typeclasses, and (sort of) ADTs / pattern matching are being discovered independently.
- beders 8y agoWas 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.
- AstralStorm 8y agoObviously 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.
- hinkley 8y agoIt’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.
- sitkack 8y agoDelegation is extremely powerful, but it is easily implementable in most OO and Functional languages, no?
- lmm 8y agoIf you have to implement it by hand you end up not doing it, especially in languages where "extends" is right there.
- pjmlp 8y agoKotlin and Groovy are two languages where you get direct support for delegation.
- didibus 8y agoWhat do you mean by delegation?
- lmm 8y agoIt'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.
- zeckalpha 8y agoSwift specifically took these ideas from Haskell, Haskell was even mentioned in comments in Swift source code for a time.