Protocol Oriented Programming

Greg Lhotellier
Feb 3, 2016 · 4 min read

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 use only one weapon but I don’t know which one to choose!”, 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!

This is a lightning talk I gave @ dotSwift ’16 The idea was to raise interest for the Protocol Oriented Programming, which was the biggest announcement of WWDC ’15 for me (along with the open source) but didn’t get the attention it deserves.

This talk was also the opportunity to make a tribute to great talks :

Edit : I changed the example of the knight’s resume, thanks to Jordan Rose

Swift Programming

The Swift Programming Language

Greg Lhotellier

Written by

⏩ swift ⏩ eat ⏩ rave ⏩ repeat

Swift Programming

The Swift Programming Language