Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Generics in
Theory and Practice
@MicheleTitolo
What We’ll Cover
What Is Generic
Programming
Super Reusable
Type Independent
The Generics Manifesto
Not A Promise
Parts Implemented In
Swift 3
Generics In The
Standard Library
Collections
Can Hold Anything
Force Type Decisions
Global Functions
Widely Applicable
Transformations
Single Type Constraint If Any
Language Limitations
Variables That Are Classes + Protocols
Protocols With Associated Types
The stdlib Is Protocol Oriented
public init<Subject, C : Collection where C.Iterator.Element == Child, C.SubSequence : Collection,
C.SubSequence.Iterator....
One-Offs
Except When Working Around
Language Limitations
Being Cool
What
Can
We
Learn?
Generics Have Purpose
Design Decision Or
Last Resort
Create True Reusability
Does Type Matter?
If It Matters,
Probably Not Generic
Surface And Enforce
Type Decisions
Using Generics Are Making
Type Decisions
Generics Enforce That Choice
Any Is Poor Form
Coming Soon
Recursive Protocol
Constraints
Associatedtypes Reference
Enclosing Type
Sequence
And Leaky Abstractions
Nested Generics
Compiler Feature
Generics Can Contain Generics
Enhanced
Existentials
Generic Types Are Enforced
At Compile Time
Existential Types Are
Enforced At Runtime
id<UITableViewDataSource,
UITableViewDelegate>
UITableViewDataSource &
UITableViewDelegate
Only Works With Concrete Protocols
In Swift 3
Workaround With Generics
Goal To Be Fixed In Swift 4
Swift Is Evolving!
Get
Involved
Photo Credits
•https://unsplash.com/search/birds?photo=XzW66yAyVBA

•https://unsplash.com/search/birds?photo=GL6ORxDMswI

...
Swift Generics in Theory and Practice
Swift Generics in Theory and Practice
Upcoming SlideShare
Loading in …5
×

Swift Generics in Theory and Practice

1,348 views

Published on

Generics are one of the features of Swift that set it apart from many other languages. Since Swift debuted, developers have been wondering when to use them and what to use them for. By looking at the standard library, which is the first piece of software to use generics, we can better understand their purpose and utility.

Published in: Software
  • Be the first to comment

Swift Generics in Theory and Practice

  1. 1. Generics in Theory and Practice @MicheleTitolo
  2. 2. What We’ll Cover
  3. 3. What Is Generic Programming
  4. 4. Super Reusable
  5. 5. Type Independent
  6. 6. The Generics Manifesto
  7. 7. Not A Promise
  8. 8. Parts Implemented In Swift 3
  9. 9. Generics In The Standard Library
  10. 10. Collections
  11. 11. Can Hold Anything
  12. 12. Force Type Decisions
  13. 13. Global Functions
  14. 14. Widely Applicable
  15. 15. Transformations
  16. 16. Single Type Constraint If Any
  17. 17. Language Limitations
  18. 18. Variables That Are Classes + Protocols
  19. 19. Protocols With Associated Types
  20. 20. The stdlib Is Protocol Oriented
  21. 21. public init<Subject, C : Collection where C.Iterator.Element == Child, C.SubSequence : Collection, C.SubSequence.Iterator.Element == Child, C.SubSequence.Index == C.Index, C.SubSequence.Indices : Collection, C.SubSequence.Indices.Iterator.Element == C.Index, C.SubSequence.Indices.Index == C.Index, C.SubSequence.Indices.SubSequence == C.SubSequence.Indices, C.SubSequence.SubSequence == C.SubSequence, C.Indices : Collection, C.Indices.Iterator.Element == C.Index, C.Indices.Index == C.Index, C.Indices.SubSequence == C.Indices>(_ subject: Subject, children: C, displayStyle: Mirror.DisplayStyle? = default, ancestorRepresentation: Mirror.AncestorRepresentation = default)
  22. 22. One-Offs
  23. 23. Except When Working Around Language Limitations
  24. 24. Being Cool
  25. 25. What Can We Learn?
  26. 26. Generics Have Purpose
  27. 27. Design Decision Or Last Resort
  28. 28. Create True Reusability
  29. 29. Does Type Matter?
  30. 30. If It Matters, Probably Not Generic
  31. 31. Surface And Enforce Type Decisions
  32. 32. Using Generics Are Making Type Decisions
  33. 33. Generics Enforce That Choice
  34. 34. Any Is Poor Form
  35. 35. Coming Soon
  36. 36. Recursive Protocol Constraints
  37. 37. Associatedtypes Reference Enclosing Type
  38. 38. Sequence
  39. 39. And Leaky Abstractions
  40. 40. Nested Generics
  41. 41. Compiler Feature
  42. 42. Generics Can Contain Generics
  43. 43. Enhanced Existentials
  44. 44. Generic Types Are Enforced At Compile Time
  45. 45. Existential Types Are Enforced At Runtime
  46. 46. id<UITableViewDataSource, UITableViewDelegate>
  47. 47. UITableViewDataSource & UITableViewDelegate
  48. 48. Only Works With Concrete Protocols In Swift 3
  49. 49. Workaround With Generics
  50. 50. Goal To Be Fixed In Swift 4
  51. 51. Swift Is Evolving!
  52. 52. Get Involved
  53. 53. Photo Credits •https://unsplash.com/search/birds?photo=XzW66yAyVBA •https://unsplash.com/search/birds?photo=GL6ORxDMswI •https://unsplash.com/search/birds?photo=kuJkUTxR0z4 •https://unsplash.com/search/birds?photo=ea4OvouLpZk •https://unsplash.com/search/birds?photo=W341a11Rt1g •https://unsplash.com/search/birds?photo=eRxKUD3S7M8 •https://unsplash.com/search/birds?photo=WooFf3yav6U •https://unsplash.com/search/birds?photo=yhnOTbw9SPY •https://www.flickr.com/photos/ 88776252@N00/5332505572/

×