Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Production Swift

Ash Furrow
February 06, 2015

Production Swift

In this talk, I use my recent real-world experience with Swift as a case study in an evaluation of Swift's production readiness. Take advantage of the lessons we learned to make the best decisions about Swift in your project.

Video is up here: http://www.thedotpost.com/2015/02/ash-furrow-swift-in-production

Ash Furrow

February 06, 2015
Tweet

More Decks by Ash Furrow

Other Decks in Programming

Transcript

  1. Production Swift
    Ash Furrow

    View Slide

  2. View Slide

  3. Objective-C

    View Slide

  4. Agenda
    1. Swift is Awesome
    2. Tools are Immature
    3. Be Informed

    View Slide

  5. Swift is
    Different

    View Slide

  6. How is it different?
    • Static vs. Dynamic
    • Prefers immutability
    • Encourages functional programming
    • Safe (well, safer)
    • Experimentation via Playgrounds

    View Slide

  7. Optional Protocol Methods
    @protocol MyProtocol
    @required
    - (void)doSomethingNecessary;
    @optional
    - (void)doSomethingOptional;
    @end

    View Slide

  8. Optional Protocol Methods
    protocol MyProtocol {
    func doSomethingNecessary()
    optional func doSomethingOptional()
    }
    // Compiler Error!

    View Slide

  9. Optional Protocol Methods
    func doSomethingNecessary()
    optional func doSomethingOptional()
    }
    @objc protocol MyProtocol {

    View Slide

  10. Objective-C Interoperability
    • Interoperability comes at the cost of Swift’s purity
    • We loose a lot of safety
    • Don’t just add @objc because it’ll make code compile

    View Slide

  11. Swift is
    Better

    View Slide

  12. Objective-C Hurts Me
    if (indexPath.section == 0) {
    if (indexPath.row == 0) {
    } else if (indexPath.row == 1) {

    } else if ...
    } else if (indexPath.section == 1) {
    if (indexPath.row == 0) {
    } else if (indexPath.row == 1) {

    } else if ...
    } else if ...

    View Slide

  13. Pattern Matching
    switch (indexPath.section, indexPath.row) {
    case (0, 0):
    case (0, 1):
    case (1, 0):
    case (1, 1):
    default:
    // nop
    }

    View Slide

  14. Pattern Matching
    case (let section, 0) where section % 2 == 0:
    case (0, let row):
    case let (0, row) where validate(row):

    View Slide

  15. Self-Evaluating Lazy Closures
    class MySweetViewController: UIViewController {
    lazy var button: UIButton = {
    let button = UIButton.buttonWithType(.System)
    // configure button
    return button
    }()
    }

    View Slide

  16. And many more …
    enums
    closures
    tuples
    generics
    compile-time awesomeness saved a kitten from a fire
    went to highschool prom with me
    function currying
    functions are closures
    array.sort(<) better terroir
    immutability by default
    type inference
    discovered penicillin
    operator overloading
    clear mutability syntax
    native collections REPL
    multiple return types
    concise
    pattern-matching

    View Slide

  17. Tools are
    Immature

    View Slide

  18. Apple Tools
    • Xcode, clang, Playgrounds, SourceKit, code signing, frameworks …
    • All are unstable
    • Causes frustrations
    • Causes delays
    • Causes hair loss

    View Slide

  19. github.com/artsy/eidolon

    View Slide

  20. Open Source
    by
    Default

    View Slide

  21. Using Swift
    doubled
    our development time

    View Slide

  22. “We don’t expect to make our deadline.”

    View Slide

  23. Eidolon Problems
    • Enterprise code signing issues with Xcode 6.1
    • Compiler segfaults with optimizations enabled
    • Constant Xcode/SourceKit crashes
    • Unit testing problems

    View Slide

  24. View Slide

  25. Burnout

    View Slide

  26. We made our deadline

    View Slide

  27. Eidolon Awesomeness
    • We helped pioneer a new way of writing iOS software
    • Created many new libraries, tools, and resources
    • Used others’ new tools and contributed bug reports and fixes
    • Learnt a tonne, shared with others

    View Slide

  28. Apple Tools
    • Someday soon, these will be ready for everyday use
    • But not today
    • You will have unanticipated problems
    • There will be no known solutions or workarounds
    • Until then, use with caution

    View Slide

  29. 3rd Party Tools
    • CocoaPods 0.36 has support for Swift
    • Tremendous amount of open source effort
    • Pre-1.0, use with caution
    • Carthage is new but promising
    • Pre-1.0, use with caution

    View Slide

  30. Be
    Informed

    View Slide

  31. Making a Choice
    • What’s your aversion to risks?
    • How hard is your deadline?
    • Why are you building something?
    • How open is your team to learning a new language?

    View Slide

  32. Why Bother?

    View Slide

  33. Swifxpert
    Become
    a

    View Slide

  34. Blog

    View Slide

  35. Risks
    Rewards
    vs.

    View Slide

  36. Be Aware
    • Don’t be afraid to revisit your decision
    • It’s OK to switch back to Objective-C

    View Slide

  37. Recap
    Swift is Awesome
    Tools are Immature
    Be Informed



    View Slide

  38. Make an informed choice.
    So start now.
    You need to know Swift to be informed.

    View Slide