Slide 1

Slide 1 text

let  swift:  Race? Jack Nutting @jacknutting [email protected]

Slide 2

Slide 2 text

let  swift:  Race?

Slide 3

Slide 3 text

struct  Sun  {          let  swift:  Race?          let  strong:  Battle?          let  wise:  Bread?          let  intelligent:  Riches?          let  knowledgeable:  Favor?        init()  {                  swift                  =  TimeAndChance()  ?  Race()      :  .None                  strong                =  TimeAndChance()  ?  Battle()  :  .None                  wise                    =  TimeAndChance()  ?  Bread()    :  .None                  intelligent      =  TimeAndChance()  ?  Riches()  :  .None                  knowledgeable  =  TimeAndChance()  ?  Favor()    :  .None          }   }

Slide 4

Slide 4 text

let  swift:  Race?

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

[[somePeople  like:ObjectiveC]  evenIn:2015]

Slide 7

Slide 7 text

[[[[[[receiver  method]  method]  method]          method]  method]  method]; receiver.method().method().method()          .method().method().method()

Slide 8

Slide 8 text

Static fixed, stable, steady, consistent motionless, frozen, inert, lifeless

Slide 9

Slide 9 text

enum

Slide 10

Slide 10 text

enum  Button  {          case  Rectangular(bounds:  CGRect,  title:  String,  font:  UIFont)          case  RoundedCorners(bounds:  CGRect,  title:  String,  font:  UIFont,                  radius:  CGFloat)   }  

Slide 11

Slide 11 text

extension  Button  {          func  draw()  {                  switch  self  {                  case  let  .Rectangular(bounds,  title,  font):                          drawRectangleButton(bounds,  title,  font)                  case  let  .RoundedCorners(bounds,  title,  font,  radius):                          drawRoundedRectangleButton(bounds,  title,  font,  radius)                  }          }   }

Slide 12

Slide 12 text

extension  Button  {          func  buttonOfPreferredSize()  -­‐>  CGSize  {                  switch  self  {                  case  let  .Rectangular(bounds,  title,  font):                          return  preferredSizeForRectangleButton(bounds,                                  title,  font)                  case  let  .RoundedCorners(bounds,  title,  font,  radius):                          return  preferredSizeForRoundedRectangleButton(bounds,                                  title,  font,  radius)                  }          }   }

Slide 13

Slide 13 text

• My Way or the Highway • Eternal Vigilance • Boilerplate

Slide 14

Slide 14 text

If a huge chunk of your enum’s code is just switching on the type, maybe you should just use a set of classes.

Slide 15

Slide 15 text

Using struct instead of class Marking classes as final Marking methods as final

Slide 16

Slide 16 text

Future developers will want the flexibility to extend your system in ways you can’t foresee.

Slide 17

Slide 17 text

–Sir Tony Hoare “Premature optimization is the root of all evil.”

Slide 18

Slide 18 text

C++

Slide 19

Slide 19 text

–Jack Nutting “All of C++ is premature optimization.”

Slide 20

Slide 20 text

Functional Programming is not a silver bullet

Slide 21

Slide 21 text

http://chris.eidhof.nl/ posts/lenses-in-swift.html

Slide 22

Slide 22 text

https://www.destroyallsoftware.com/ talks/boundaries

Slide 23

Slide 23 text

Conclusions Sometimes enums aren’t the answer. Static has drawbacks. All of C++ is premature optimization. FP is not a silver bullet.

Slide 24

Slide 24 text

Jack Nutting @jacknutting [email protected] let  swift:  Race?