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

Cocoa is the new Carbon: The Future of Apple’s Beloved Framework

Cocoa is the new Carbon: The Future of Apple’s Beloved Framework

In this talk, Adrian provides lots of speculation and highly arguable unverified gossip, about how the design of Swift will lead Apple to redesign Cocoa into new directions, and maybe replacing it altogether. Some code examples will help him defend a point that nobody outside of Cupertino can sustain for sure.

Presentation given in Zürich, Switzerland, February 26th, 2015.

The speech of the presentation can be found here:
https://akos.ma/blog/cocoa-is-the-new-carbon-the-future-of-apples-beloved-framework/

Adrian Kosmaczewski

February 26, 2015
Tweet

More Decks by Adrian Kosmaczewski

Other Decks in Technology

Transcript

  1. Cocoa is the new Carbon
    The Future of Apple’s Beloved Framework
    © akosma 2015 1

    View full-size slide

  2. Adrian Kosmaczewski
    @akosma
    https://github.com/akosma
    © akosma 2015 2

    View full-size slide

  3. “Everything changes
    and nothing stands
    still.”
    Heraclitus of Ephesus, (535 - 475 BC)
    © akosma 2015 3

    View full-size slide

  4. “Πάντα χωρεῖ καὶ
    οὐδὲν μένει”
    Ἡράκλειτος
    © akosma 2015 4

    View full-size slide

  5. © akosma 2015 5

    View full-size slide

  6. © akosma 2015 6

    View full-size slide

  7. 6502 → 68000 → PowerPC → Intel → ARM
    © akosma 2015 7

    View full-size slide

  8. 8 bit → 16 bit → 32 bit → 64 bit
    © akosma 2015 8

    View full-size slide

  9. Integer Basic
    → Object Pascal & MacApp
    → C++ & Metrowerks PowerPlant
    → Objective-C & Cocoa
    → Swift & Standard Library
    © akosma 2015 9

    View full-size slide

  10. Procedural → Object Oriented →
    Functional
    © akosma 2015 10

    View full-size slide

  11. “"Plus ça change,
    plus c'est la même
    chose."”
    Jean-Baptiste Alphonse Karr (1808 - 1890)
    © akosma 2015 11

    View full-size slide

  12. Heraclitus ! Jean-Baptiste
    © akosma 2015 12

    View full-size slide

  13. Transitional Technologies
    © akosma 2015 13

    View full-size slide

  14. Mac 68k
    Emulator
    1992 - 2008 (!)
    © akosma 2015 14

    View full-size slide

  15. Macintosh
    Application
    Environment
    1994 - 1998
    © akosma 2015 15

    View full-size slide

  16. Classic
    Environment
    Deprecated in
    OS X 10.5
    "Leopard"
    2000 - 2008
    © akosma 2015 16

    View full-size slide

  17. Carbon
    Deprecated in OS X 10.8 "Mountain
    Lion"
    2000 - 2012
    #if __i386__
    #include
    #else
    #include
    #endif
    © akosma 2015 17

    View full-size slide

  18. The LLVM Compiler Infrastructure
    2003 - now
    © akosma 2015 18

    View full-size slide

  19. Rosetta
    Deprecated in
    OS X 10.7 "Lion"
    2006 - 2011
    © akosma 2015 19

    View full-size slide

  20. Universal Binaries
    © akosma 2015 20

    View full-size slide

  21. Objective-C 2.0 (1/2)
    2006 - now
    // Before
    @implementation SomeClass
    - (NSObject *)stuff {
    return _stuff;
    }
    - (void)setStuff:(NSObject *)newStuff {
    [newStuff retain];
    [_stuff release];
    _stuff = newStuff;
    }
    @end
    © akosma 2015 21

    View full-size slide

  22. Objective-C 2.0 (2/2)
    2006 - now
    // After
    @interface SomeClass
    @property (nonatomic, strong) NSObject *stuff;
    @end
    © akosma 2015 22

    View full-size slide

  23. LLVM
    Around 2009
    → Xcode Static Analyzer
    → Automatic Resource Counting (ARC)
    © akosma 2015 23

    View full-size slide

  24. Cocoa
    1988 - now
    Deprecated in 5… 4… 3… !
    @import Cocoa;
    © akosma 2015 24

    View full-size slide

  25. nullable Objective-C Pointers 1 !
    @interface LocationDataController : NSObject
    @property (nonnull, nonatomic) NSArray *locations;
    @property (nullable, nonatomic) Location *latestLocation;
    - (void)addPhoto:(nonnull Photo *)photo
    forLocation:(nonnull Location *)location;
    - (nullable Photo *)photoForLocation:(nonnull Location *)location;
    @end
    1 "Swift 1.2" by Nate Cook
    © akosma 2015 25

    View full-size slide

  26. Cocoa should remain for
    backwards compatibility during
    10 years
    at least, until 2025!
    © akosma 2015 26

    View full-size slide

  27. © akosma 2015 27

    View full-size slide

  28. What is Swift?
    © akosma 2015 28

    View full-size slide

  29. Modern
    Safe
    Fast
    Interoperable
    © akosma 2015 29

    View full-size slide

  30. © akosma 2015 30

    View full-size slide

  31. Features
    © akosma 2015 31

    View full-size slide

  32. Protocols, Pattern Matching
    Generics, Tuples, Optionals, Enums
    Strong Typing, Type Inference
    Structs, Functions
    © akosma 2015 32

    View full-size slide

  33. OOP features of Swift are based in
    Functional
    primitives and mechanisms!
    © akosma 2015 33

    View full-size slide

  34. Inspiration
    © akosma 2015 34

    View full-size slide

  35. C#, JavaScript,
    Haskell, Erlang,
    Ruby, C++, Java, Scala
    © akosma 2015 35

    View full-size slide

  36. © akosma 2015 36

    View full-size slide

  37. How would the successor of Cocoa
    look like?
    © akosma 2015 37

    View full-size slide

  38. Gedankenexperiment !
    © akosma 2015 38

    View full-size slide

  39. © akosma 2015 39

    View full-size slide

  40. Swift Standard Library
    let array = [10, 200, 3000]
    for (pos, value) in enumerate(array) {
    println("\(pos): \(value)")
    }
    // 0: 10
    // 1: 200
    // 2: 3000
    © akosma 2015 40

    View full-size slide

  41. LINQ (1/2)
    public void linq()
    {
    List products = GetProductList();
    var expensive =
    from p in products
    where p.Stock > 0 && p.Price > 1000
    select p;
    foreach (var product in expensive)
    {
    Console.WriteLine(product.Name);
    }
    }
    © akosma 2015 41

    View full-size slide

  42. LINQ (2/2)
    func linq(){
    let products = productsList()
    let expensive = products
    .find { p in p.stock > 0 && p.price > 1000 }
    for p in expensive {
    println(p.name)
    }
    }
    © akosma 2015 42

    View full-size slide

  43. © akosma 2015 43

    View full-size slide

  44. Dollar.swift
    let double = { (params: Int...) -> [Int] in
    return $.map(params) { $0 * 2 }
    }
    let subtractTen = { (params: Int...) -> [Int] in
    return $.map(params) { $0 - 10 }
    }
    let doubleSubtractTen = $.compose(double, subtractTen)
    doubleSubtractTen(5, 6, 7)
    => [0, 2, 4]
    © akosma 2015 44

    View full-size slide

  45. Alamofire
    let user = "user"
    let password = "password"
    Alamofire.request(.GET, "http://somewhere.over/the.rainbow")
    .authenticate(user: user, password: password)
    .validate(statusCode: 200..<300)
    .responseString { (_, _, string, _) in
    println(string)
    }
    .responseJSON { (_, _, JSON, _) in
    println(JSON)
    }
    © akosma 2015 45

    View full-size slide

  46. Notification Center (1/3)
    struct Notification {
    let name: String
    }
    func postNotification(note: Notification, value: A) {
    let userInfo = ["value": Box(value)]
    let center = NSNotificationCenter.defaultCenter()
    center.postNotificationName(note.name,
    object: nil,
    userInfo: userInfo)
    }
    © akosma 2015 46

    View full-size slide

  47. Notification Center (2/3)
    class NotificationObserver {
    let observer: NSObjectProtocol
    init(notification: Notification, block aBlock: A -> ()) {
    let center = NSNotificationCenter.defaultCenter()
    observer = center.addObserverForName(notification.name,
    object: nil,
    queue: nil) { note in
    if let value = (note.userInfo?["value"] as? Box)?.unbox {
    aBlock(value)
    }
    }
    }
    deinit { … }
    }
    © akosma 2015 47

    View full-size slide

  48. Notification Center (3/3)
    let notif: Notification = Notification(name: "Global panic")
    let myError: NSError = NSError(domain: "io.objc.sample",
    code: 42,
    userInfo: [:])
    postNotification(notif, myError)
    let observer = NotificationObserver(notification: notif) { err in
    println(err.localizedDescription)
    }
    © akosma 2015 48

    View full-size slide

  49. Events (1/2)
    class Event {
    typealias EventHandler = T -> ()
    private var eventHandlers = [EventHandler]()
    func addHandler(handler: EventHandler) {
    eventHandlers.append(handler)
    }
    func raise(data: T) {
    for handler in eventHandlers {
    handler(data)
    }
    }
    }
    © akosma 2015 49

    View full-size slide

  50. Events (2/2)
    let event = Event()
    event.addHandler { println("Hello") }
    event.addHandler { println("World") }
    event.raise()
    // What?
    let event = Event<(String, String)>()
    event.addHandler { a, b in println("Hello \(a), \(b)") }
    event.raise("First", "Second")
    © akosma 2015 50

    View full-size slide

  51. SwiftyUserDefaults
    Defaults["color"] = "red"
    Defaults["launchCount"] = 0
    Defaults["color"] ?= "white"
    Defaults["firstLaunchAt"].date // returns NSDate?
    Defaults["launchCount"] += 1
    if !Defaults.hasKey("hotkey") {
    Defaults.remove("hotkeyOptions")
    }
    © akosma 2015 51

    View full-size slide

  52. SwiftMoment
    let today = moment()
    let before = moment("2015-01-19")
    let earlier = before < today // true
    let soon = today + 1.hours
    let duration = 5.hours + 56.minutes
    let format = "EE yyyy/dd MMMM HH:mm"
    let birthday = moment("Tue 1973/4 September 12:30", format)!
    let str = birthday.format(dateFormat: "EE QQQQ yyyy/dd/MMMM")
    // "Tue 3rd quarter 1973/04/September"
    © akosma 2015 52

    View full-size slide

  53. Are we there yet?
    Hint: no.
    © akosma 2015 53

    View full-size slide

  54. Protocols, Pattern Matching
    Generics, Tuples, Optionals, Enums
    Strong Typing, Type Inference
    Structs, Functions
    © akosma 2015 54

    View full-size slide

  55. Functions and structs
    instead of objects and classes
    © akosma 2015 55

    View full-size slide

  56. Not all is OK
    What about reflection? Documentation? UI?
    © akosma 2015 56

    View full-size slide

  57. Time will tell !
    © akosma 2015 57

    View full-size slide

  58. Thanks! !
    © akosma 2015 58

    View full-size slide

  59. Adrian Kosmaczewski
    @akosma
    https://github.com/akosma
    © akosma 2015 59

    View full-size slide

  60. Special thanks to
    Junior Bontognali @bontojr for the organisation
    Fabrice Truillot de Chambrier @fabricetdc
    And the great people I follow on Twitter
    © akosma 2015 60

    View full-size slide

  61. Slides created with Deckset
    © akosma 2015 61

    View full-size slide