3 ms·
I haven't seen it mentioned how you would do composition in Swift. I assume it has a feature like Scala's traits –– hopefully with a better syntax? Does anyone
by picardo 12y ago
I haven't seen it mentioned how you would do composition in Swift. I assume it has a feature like Scala's traits –– hopefully with a better syntax? Does anyone know?
- matthewmacleod 12y agoI'm not that familiar with Scala, but aren't traits basically interfaces? I imagine Swift's protocols are the same deal.
- krat0sprakhar 12y agoThis might be helpful - https://leverich.github.io/swiftislikescala/#protocol https://leverich.github.io/swiftislikescala/#protocol
- virtualwhys 12y agoThanks for that, interesting comparison. Extensive usage of var in the examples, that's not suggested best practice in Scala, val is king, but I guess for one-to-one comparison each language does indeed express mutability similarly. `return` is implicit if expression is the last in a block, so none of the `return` statements on the Scala side are needed. Pretty interesting grab bag of functionality, I'm seeing a lot of Scala, but then bits of Python, Groovy, and Kotlin (extension methods) as well.
- gress 12y agoNo. Swift doesn't have traits. It has protocols but these can't currently contain implementation. Implementation is currently strictly based on single inheritance with open classes (through extension).