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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

  5. © akosma 2015 5

    View Slide

  6. © akosma 2015 6

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  12. Heraclitus ! Jean-Baptiste
    © akosma 2015 12

    View Slide

  13. Transitional Technologies
    © akosma 2015 13

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  20. Universal Binaries
    © akosma 2015 20

    View 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 Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

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

    View Slide

  27. © akosma 2015 27

    View Slide

  28. What is Swift?
    © akosma 2015 28

    View Slide

  29. Modern
    Safe
    Fast
    Interoperable
    © akosma 2015 29

    View Slide

  30. © akosma 2015 30

    View Slide

  31. Features
    © akosma 2015 31

    View Slide

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

    View Slide

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

    View Slide

  34. Inspiration
    © akosma 2015 34

    View Slide

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

    View Slide

  36. © akosma 2015 36

    View Slide

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

    View Slide

  38. Gedankenexperiment !
    © akosma 2015 38

    View Slide

  39. © akosma 2015 39

    View 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 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 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 Slide

  43. © akosma 2015 43

    View 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 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 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 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 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 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 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 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 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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  57. Time will tell !
    © akosma 2015 57

    View Slide

  58. Thanks! !
    © akosma 2015 58

    View Slide

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

    View 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 Slide

  61. Slides created with Deckset
    © akosma 2015 61

    View Slide