- Extension methods: Simpler, less bloat, more predictable, extensible by third parties.
- Mixins: More flexible (since classes can override). Designer control for uniformity, but less extensible. Bloats compiled code. More complicated than static extension methods.
- Implicit conversions: Extensible but results in more complicated semantics. (I understand that C# also has implicit conversion, but it's not meant for this use case to my understanding.)
My own idea is something I call a "role" which is a combination of a runtime-erased type alias with optional extension methods. But I won't go in depth right now.
Have you realized how short-sighted this post was yet?
ReplyDeleteEven C# people who have never heard of Scala can tell you that the weaknesses of extension methods are severe and potentially dangerous, and readily apparent once you get over the initial "Cool!" factor of Enumerable and actually start rolling your own.
I don't see how extension methods are much different than static overloading, such as what Java and C++ provide, but I haven't spent enough time in C# to know for sure. Do you have any references on the matter that I can review?
ReplyDeleteHowever, I've lately become more a fan of arbitrary multiple dynamic dispatch, ignoring OOP entirely. And error out for multiple matches. Well, that's in theory, since I haven't used such a system in practice, although I know they exist.