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://gist.github.com/akosma/b94cbd3c28f562d1150a

The source code of these slides can be found here:
https://gist.github.com/akosma/f65129fcddddddb6668e

53619e4417778923cc65a51683e850a0?s=128

Adrian Kosmaczewski

February 26, 2015
Tweet

Transcript

  1. Cocoa is the new Carbon The Future of Apple’s Beloved

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

  3. “Everything changes and nothing stands still.” Heraclitus of Ephesus, (535

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

  5. © akosma 2015 5

  6. © akosma 2015 6

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

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

    bit © akosma 2015 8
  9. Integer Basic → Object Pascal & MacApp → C++ &

    Metrowerks PowerPlant → Objective-C & Cocoa → Swift & Standard Library © akosma 2015 9
  10. Procedural → Object Oriented → Functional © akosma 2015 10

  11. “"Plus ça change, plus c'est la même chose."” Jean-Baptiste Alphonse

    Karr (1808 - 1890) © akosma 2015 11
  12. Heraclitus ! Jean-Baptiste © akosma 2015 12

  13. Transitional Technologies © akosma 2015 13

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

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

  16. Classic Environment Deprecated in OS X 10.5 "Leopard" 2000 -

    2008 © akosma 2015 16
  17. Carbon Deprecated in OS X 10.8 "Mountain Lion" 2000 -

    2012 #if __i386__ #include <Carbon/Carbon.h> #else #include <Carbon.h> #endif © akosma 2015 17
  18. The LLVM Compiler Infrastructure 2003 - now © akosma 2015

    18
  19. Rosetta Deprecated in OS X 10.7 "Lion" 2006 - 2011

    © akosma 2015 19
  20. Universal Binaries © akosma 2015 20

  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
  22. Objective-C 2.0 (2/2) 2006 - now // After @interface SomeClass

    @property (nonatomic, strong) NSObject *stuff; @end © akosma 2015 22
  23. LLVM Around 2009 → Xcode Static Analyzer → Automatic Resource

    Counting (ARC) © akosma 2015 23
  24. Cocoa 1988 - now Deprecated in 5… 4… 3… !

    @import Cocoa; © akosma 2015 24
  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
  26. Cocoa should remain for backwards compatibility during 10 years at

    least, until 2025! © akosma 2015 26
  27. © akosma 2015 27

  28. What is Swift? © akosma 2015 28

  29. Modern Safe Fast Interoperable © akosma 2015 29

  30. © akosma 2015 30

  31. Features © akosma 2015 31

  32. Protocols, Pattern Matching Generics, Tuples, Optionals, Enums Strong Typing, Type

    Inference Structs, Functions © akosma 2015 32
  33. OOP features of Swift are based in Functional primitives and

    mechanisms! © akosma 2015 33
  34. Inspiration © akosma 2015 34

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

    2015 35
  36. © akosma 2015 36

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

    2015 37
  38. Gedankenexperiment ! © akosma 2015 38

  39. © akosma 2015 39

  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
  41. LINQ (1/2) public void linq() { List<Product> 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
  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
  43. © akosma 2015 43

  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
  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
  46. Notification Center (1/3) struct Notification<A> { let name: String }

    func postNotification<A>(note: Notification<A>, value: A) { let userInfo = ["value": Box(value)] let center = NSNotificationCenter.defaultCenter() center.postNotificationName(note.name, object: nil, userInfo: userInfo) } © akosma 2015 46
  47. Notification Center (2/3) class NotificationObserver { let observer: NSObjectProtocol init(notification:

    Notification<A>, 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<A>)?.unbox { aBlock(value) } } } deinit { … } } © akosma 2015 47
  48. Notification Center (3/3) let notif: Notification<NSError> = 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
  49. Events (1/2) class Event<T> { 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
  50. Events (2/2) let event = Event<Void>() 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
  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
  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
  53. Are we there yet? Hint: no. © akosma 2015 53

  54. Protocols, Pattern Matching Generics, Tuples, Optionals, Enums Strong Typing, Type

    Inference Structs, Functions © akosma 2015 54
  55. Functions and structs instead of objects and classes © akosma

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

    akosma 2015 56
  57. Time will tell ! © akosma 2015 57

  58. Thanks! ! © akosma 2015 58

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

  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
  61. Slides created with Deckset © akosma 2015 61