Skip to content
0:00 / 0:00

#protocolswithassociatedtypes#generics#swift

Alexis Gallagher - Protocols with Associated Types

Functional Swift

3.4K subscribers • 1 video on Hallway

YouTube
  • Recommended by 4 people: 4 in engineering communities.
  • A classic. People kept recommending it from 2016 to 2019.
  • Presented by Alexis Gallagher
  • An opinion. It argues one side of a question engineers disagree on.

Advanced. Deep dive for people who know the field.

32K views10 years ago4 recommendations

Programming languagesSoftware designSwiftLanguage design and type systemsFunctional programming

Alexis Gallagher explains the complexities, design assumptions, and common pitfalls of Protocols with Associated Types in Swift.

2015.funswiftconf.com

Why it's here

4 people recommend this

What people say. Highly recommended as the canonical, eye-opening talk explaining the design and difficulties of Swift's Protocols with Associated Types.

Moments people linked to

u/applishishin r/swift • Recommends

On “What's the worst part of Swift in your opinion?”

There's far too much to put in a comment. The canonical PATs video goes over many of the issues. For example, the "Protocols as Types" section of the manual says "Because it’s a type, you can use a protocol in many places where other types are allowed, including:" and then lists 3 places that protocols with associated types *cannot* be used. It's probably easiest to think of PATs as completely distinct from protocols. Reusing the word "protocol" seems to have been much more confusing than helpful. > How are protocols with associated types supposed to be used in your opinion? When using an interface in the standard library that requires them.

u/bufferingin r/swift • Recommends

On “What was the most eye-opening Swift video you've ever watched?”

That one on Protocols with Associated Types. It's a must-watch. link to this video

u/applishishin r/swift • Recommends

On “What are the Java equivalent of Swift terminologies?”

The video here has a table with common object-orientation names across many languages, including Swift.
3View on Reddit

u/applishishin r/swift • Recommends

On “[Help] - Feedback on Apple's Swift Documentation”

Someone (maybe Steve Yegge?) once said that what was missing from most software documentation is a list of *assumptions* held by the designers of the software. This is absolutely true with Swift. The documentation tells you all the whats, but none of the whys. Once you've learned 90% of Swift, the last 10% isn't so bad because by then you've reverse-engineered the major design assumptions, so you can forward-re-engineer the knowledge gaps that remain. But that first 90% is a bear because you have no idea why Swift's designers chose anything they did. Apple made this especially difficult. Their original announcement declared that Swift was "Objective-C without the C!", but that's not ev…

u/swiftonistain r/swift • Recommends

On “Why can you not declare a variable of arbitrary type conforming to some protocol in Swift?”

There's a great video talk that explains how "Protocols with Associated Types" ("Protocols with Associated Pain") are basically completely different from "protocols" (in Objective-C, or ordinary Swift protocols without associated types), and if you assume they work like protocols, then much of the documentation is a complete lie.

u/swiftonistain r/swift • Recommends

On “Grouping elements of a Sequence in Swift”

Ugh. There's many things I like about Swift, but "moar generics (for the sake of generics)" isn't one of them. I wish I were smart enough to use generics. I've watched this video twice and I still don't understand half of it. I'm sure there's some clever machinations going on in Swift's type system, if I had a PhD in optimizing compilers like Chris, but I only have a wimpy bachelor's degree in computer science (and it's been a decade since I last wrote a compiler) so it's mostly a mystery to me. In all my years using Objective-C, I'd gotten roughly zero type errors. That's just not a problem I ever had. (Or look at any Ruby or Python program. Those guys don't seem too bothered by i…

u/nextnextstepin r/swift • Recommends

On “Should I learn Swift”

Everything? I would love to hear your "easy" explanation of Protocols with Associated Types (a.k.a. Protocols with Associated Pain). I've watched this hourlong talk several times and I still don't fully understand what the Swift designers think they were trying to solve or how I'm expected to use this to solve actual programming problems I have ... or why this was so critically important that it was worthwhile to make Equatable a pain in the ass to use. I maintain that if the key to understanding a language is reading an old article from the Journal of Functional Programming to discover how it combines the best features of the SML and Haskell type systems (but with Simula style syntax,…