It’s been about two years since Apple came out with Swift, which they call a protocol-oriented language. Since then, articles (and a StackOverflow question) have emerged explaining the difference between object-orientation and protocol-orientation. A few examples of these articles are as follows:
- Is Protocol Oriented Swift Better than Object Oriented Swift?
- If you’re subclassing, you’re doing it wrong.
- How Protocol Oriented Programming in Swift saved my day?
- What is Protocol Oriented Programming in Swift?
Arguments against object-orientation include inheritance and classes, and you’ll know those are not what object-orientation is about if you’ve read my previous posts.
The only reason why Swift is dubbed a protocol-oriented language is to place emphasis on protocols and because of the mechanisms Apple added around protocols, such as protocol extensions. Apple even has a WWDC presentation titled “Protocol-Oriented Programming in Swift”. In that talk, Dave Abrahams portrays a guy named Crusty as an old-school programmer who dislikes object-oriented programming because of qualities such as inheritance and automatic sharing. Dave then uses Crusty’s dislike of object-orientation as a pivot point to support protocol-oriented programming in Swift. The implication here is that protocol-orientation solves Crusty’s problems regarding object-orientation.
Well, I found Crusty. Here he is, and I think you’ll find it interesting to hear what he has to say. It seems like Dave’s talk was a step in the right direction in terms of mindset, albeit premature.