-
Notifications
You must be signed in to change notification settings - Fork 7
philosophy
you can use protocols, just not existential containers!
And I may add that. My concern is it’s adding in inefficiency. Right now it forces you to write code using generics for polymorphism instead of the old fashioned approaches with object pointers, virtual method tables and dynamic method calls.
To summarise it, Swift allows a new form of polymorphism using generics and protocols with value types, this makes fast, efficient, powerful code that scales well and is “the future” but it can be a bit arcane in places…
The key concept is static method calls. Or put more precisely, static linking.
Everything gets optimised down to the simplest possible code using “compiler magic”.
Swift also allows you to use older polymorphism like classes, virtual methods and the equivalent of Java and C# interface types. This is slower and Apple tend to try and encourage people to use the more modern approach where possible, but they acknowledge there’s a lot of legacy code and design patterns over the past 30 years of work on object orientation that they really need to support, because not everyone is an Erlang/Haskell programmer or whatever (I’m not enough of a compiler/language nerd to know… yet…)
The key concept there is dynamic method calls.
Swift for Arduino takes away the last option, at least for now, and forces you to use either old fashioned functions or value type programming with generics for polymorphism.