Protocol Oriented Programming was one of the biggest announcement of WWDC ‘15 but it didn’t get the attention it deserves. To get its basic idea and raise interest for the subject, Grégoire argues that object, functional and protocol oriented programming can be compared to 3 princesses...
Once upon a time, in the *OP kingdom, not really far away, there was a princess called OOP.
Everyone knew OOP and lots of people liked her. One day, she had a little sister, named POP.
People didn’t like POP. Some found her too young, others didn’t understand when she spoke. But the truth is that people were afraid. They were afraid of the old Crusty and the old Crusty didn’t like the princess POP.
Because of that, poor princess POP regularly found herself alone in its tiny castle at the kingdom’s border.
One day a brave knight of the kingdom decided to visit princess POP. Villagers recommended not to do so because the old Crusty lived on the way. “I’m not afraid of Crusty” said the knight and he started his journey to POP’s castle. On the way he passed Crusty’s house but doors and shutters were closed. In fact, the old Crusty was dead long ago.
“That’s better” thought the knight and he went his way. He arrived at the castle and met princess POP for the 1st time. She looked a bit like her old sister but younger, fresher and more joyful.
A party was organized to welcome the knight. He was delighted, but also surprised. He was used to parties at OOP’s castle, but it was always very formal, very family. For example, if UIButton was invited, you could be sure that his mother, UIView, would be there, and the old grandmother NSObject would be there as well. With POP, everything was different. UIButton could celebrate with a String and an Int. The knight found the atmosphere more friendly and decided to stay a few days to get to know the princess better.
The next morning at breakfast, while they were eating macdonalds and drinking starbucks, the knight asked the princess to create an array of protocol without associated types. She did it with a smile.
Then, he asked her to create an array of protocol with associated types. She froze and refused categorically. The knight soon understood that the princess had an evil twin.
This evil twin was called PAT and everything the princess agreed to do, he refused. After a few days, the knight found himself repeatedly facing PAT. He was disappointed. Maybe that’s why people didn’t like POP, maybe they had met PAT too? The knight hesitated to leave until another time he met PAT. That day, the knight was struggling with his resume.
“I can handle so many weapons, it’s impossible to write them all!”, said the knight. Then, PAT came and told him ”Try this!”.
That was perfect. After that, the knight and PAT became BFFs. The knight decided to settle permanently at POP’s castle but he continued to regularly visit OOP.
And to conclude, but it’s a secret between us, he was also partying at princess FOP!