Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Interpreting Objective C

906 views

Published on

I've been working in the iOS community since 2008, and I've seen many people come to Objective-C.

I've also seen many of them complain about it.

I called this talk "Interpreting Objective-C" because I hope it will help you understand Objective-C a little better, and especially realize that when people describe Objective-C in terms of brackets and colons, they're missing its true nature.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Interpreting Objective C

  1. 1. Interpreting Objective-C @timburks
  2. 2. ν “What’s new (nu)?” Interpreting Objective-C. © Tim Burks. March 4, 2014
  3. 3. c/λ “C over lambda.” Interpreting Objective-C. © Tim Burks. March 4, 2014
  4. 4. Usage Desire Craft Insight Interpreting Objective-C. © Tim Burks. March 4, 2014
  5. 5. Desire Interpreting Objective-C. © Tim Burks. March 4, 2014
  6. 6. Beliefs about Better Interpreting Objective-C. © Tim Burks. March 4, 2014
  7. 7. 1 In any resource-constrained environment, performance is everything. Interpreting Objective-C. © Tim Burks. March 4, 2014
  8. 8. 2 All environments of value are resource-constrained. Interpreting Objective-C. © Tim Burks. March 4, 2014
  9. 9. 3 Performance is device performance and developer performance. Interpreting Objective-C. © Tim Burks. March 4, 2014
  10. 10. 4 The number of developers required to create a system is its biggest weakness. Interpreting Objective-C. © Tim Burks. March 4, 2014
  11. 11. 5 Stability and productivity are a developer's top two priorities, in that order. Interpreting Objective-C. © Tim Burks. March 4, 2014
  12. 12. 6 • Simplicity allows speed. Speed increases opportunity. • Simplicity allows control. Control reduces risk. Interpreting Objective-C. © Tim Burks. March 4, 2014
  13. 13. 7 • The C platform has consistently offered the best run time/power/capability performance for developers. • Lisp-style languages have offered the greatest capabilities of abstraction. Interpreting Objective-C. © Tim Burks. March 4, 2014
  14. 14. Insight Interpreting Objective-C. © Tim Burks. March 4, 2014
  15. 15. Observation Objective-C solves many problems in bridging C with high level languages. • Introspectable: no glue code is needed to bind to compiled objects. • Dynamic: we can add to the Objective-C runtime at run time. Interpreting Objective-C. © Tim Burks. March 4, 2014
  16. 16. So What’s Nu? • Nu is an interpreted dialect of Lisp that parses into Objective C objects that can be evaluated to perform computations. • Nu interacts directly with the Objective-C runtime to create and use classes, methods, and objects. Interpreting Objective-C. © Tim Burks. March 4, 2014
  17. 17. Craft Interpreting Objective-C. © Tim Burks. March 4, 2014
  18. 18. Parsing Nu (puts (+ 2 2))! NuCell NuCell puts Nu_puts_operator NuCell NuCell NuCell + 2 2 Nu_add_operator NSNumber NSNumber Interpreting Objective-C. © Tim Burks. March 4, 2014
  19. 19. Evaluating Nu - (id) evaluateWithContext:(NSMutableDictionary *) context NuCell NuCell puts Nu_puts_operator NuCell NuCell NuCell + 2 2 Nu_add_operator NSNumber NSNumber Interpreting Objective-C. © Tim Burks. March 4, 2014
  20. 20. Operators (+ 2 (/ 14 7)) ! ! Objects (UIStoryboard storyboardWithName:name bundle:nil) ! ! Interpreting Objective-C. © Tim Burks. March 4, 2014
  21. 21. Interacting with the Runtime ((UIView alloc) initWithFrame:’(0 0 100 100))! ! Nu evaluation can resolve symbols by looking up classes and methods in the Objective-C runtime. Nu evaluation uses Objective-C method signatures to make method calls with appropriately-typed arguments. Interpreting Objective-C. © Tim Burks. March 4, 2014
  22. 22. Interacting with the Runtime (class MyClass is NSObject ! (- hello is ! (puts “hello"))) The Nu class operator can be used to define new classes and to add methods to existing ones. Interpreting Objective-C. © Tim Burks. March 4, 2014
  23. 23. The Nu Shell % nush! Nu Shell.! % (class MyClass is NSObject ! (- hello is (puts "hello")))! ()! % (set myobject (MyClass new))! <MyClass:7fdb6863dd10>! % (myobject hello)! hello! ()! Interpreting Objective-C. © Tim Burks. March 4, 2014
  24. 24. Usage Interpreting Objective-C. © Tim Burks. March 4, 2014
  25. 25. Generate a plist ! (set me (dict name:"Tim Burks"! company:"Radtastical Inc."! address:(dict street:"220 South California Avenue, Suite 250"! city:"Palo Alto"! state:"CA"! zip:"94306")! projects:(array (dict name:"Silicon Valley iOS Developers' Meetup"! url:"http://meetup.com/sviphone")! (dict name:"Renaissance"! url:"http://renaissance.io")! (dict name:"Open Radar"! url:"http://openradar.io")! (dict name:"Nu"! url:"http://programming.nu"))))! ! ((me XMLPropertyListRepresentation) writeToFile:"tim.plist" atomically:NO)! Interpreting Objective-C. © Tim Burks. March 4, 2014
  26. 26. <?xml version="1.0" encoding="UTF-8"?>! <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">! <plist version="1.0">! <dict>! ! <key>address</key>! ! <dict>! ! ! <key>city</key>! ! ! <string>Palo Alto</string>! ! ! <key>state</key>! ! ! <string>CA</string>! ! ! <key>street</key>! ! ! <string>220 South California Avenue, Suite 250</string>! ! ! <key>zip</key>! ! ! <string>94306</string>! ! </dict>! ! <key>company</key>! ! <string>Radtastical Inc.</string>! ! <key>name</key>! ! <string>Tim Burks</string>! ! <key>projects</key>! ! <array>! ! ! <dict>! ! ! ! <key>name</key>! ! ! ! <string>Silicon Valley iOS Developers' Meetup</string>! ! ! ! <key>url</key>! ! ! ! <string>http://meetup.com/sviphone</string>! ! ! </dict>! ! ! <dict>! ! ! ! <key>name</key>! ! ! ! <string>Renaissance</string>! ! ! ! <key>url</key>! ! ! ! <string>http://renaissance.io</string>! ! ! </dict>! ! ! <dict>! ! ! ! <key>name</key>! ! ! ! <string>Open Radar</string>! ! ! ! <key>url</key>! ! ! ! <string>http://openradar.io</string>! ! ! </dict>! ! ! <dict>! ! ! ! <key>name</key>! ! ! ! <string>Nu</string>! ! ! ! <key>url</key>! ! ! ! <string>http://programming.nu</string>! ! ! </dict>! ! </array>! </dict>! </plist>! Interpreting Objective-C. © Tim Burks. March 4, 2014
  27. 27. Call a Remote API ;;! ;; test google geocoding API ! ;; API is limited to 2500 requests/(ip-address*day)! ;;! ! (load "RadHTTP")! (load "RadJSON")! ! (set street "1675 Owens Street")! (set city "San Francisco")! (set state "CA")! ! (set parameters (dict sensor:"false"! address:(+ street " "! city ", "! state " "! )))! (set query (parameters urlQueryString))! (set path (+ "http://maps.googleapis.com/maps/api/geocode/json?" query))! (set string (NSString stringWithContentsOfURL:(NSURL URLWithString:path)))! (set geocoding (string JSONValue))! ! (puts (geocoding description)) Interpreting Objective-C. © Tim Burks. March 4, 2014
  28. 28. {! results = ! (! …! ! geometry = {! location = {! lat = "37.76800009999999";! lng = "-122.3934754";! };! "location_type" = ROOFTOP;! viewport = {! northeast = {! lat = "37.76934908029149";! lng = "-122.3921264197085";! };! southwest = {! lat = "37.7666511197085";! lng = "-122.3948243802915";! };! };! };! types = (! "street_address"! );! }! );! status = OK;! }! Interpreting Objective-C. © Tim Burks. March 4, 2014
  29. 29. Write Unit Tests ;; test_array.nu! ;; tests for Nu array extensions.! ;;! ;; Copyright (c) 2007 Tim Burks, Radtastical Inc.! ! (class TestArray is NuTestCase! ! (- testCreate is! (set a (NSMutableArray arrayWithList:'(1 2)))! (a << "three")! (assert_equal 3 (a count))! (assert_equal 2 (a 1))! (assert_equal "three" (a 2)))! ! (- testEach is! (set i 0)! (set a (array 0 1 2))! (a each:! (do (x)! (assert_equal i x)! (set i (+ i 1))))! ;; iteration with break! (set a (array 0 1 2 3 4 5 6))! (set sum 0)! (a each:! (do (x)! Interpreting Objective-C. © Tim Burks. March 4, 2014
  30. 30. [hebephrenia:~/nu] tim% nutest test/test_array.nu! ! TestArray: running! --- testCreate! --- testEach! --- testEachInReverse! --- testEachWithIndex! --- testIndexing! --- testSortUsingBlock! --- testSortedArrayUsingBlock! --- testSortedArrayUsingSelector! TestArray: completed 8 tests/32 assertions/0 failures/0 errors! ! 2014-03-03 19:52:41.147 nush[10592:d07] All: completed 8 tests/32 assertions/0 failures/0 errors! ! 2014-03-03 19:52:41.148 nush[10592:d07] SUCCESS (0 failures, 0 errors) Interpreting Objective-C. © Tim Burks. March 4, 2014
  31. 31. Build iOS apps <dict> <key>action</key> <string>push sessions/2014/day/1</string> <key>image</key> <dict> <key>filename</key> <string>2014_bill_budge.jpg</string> <key>mask</key> <string>circle</string> <key>position</key> <string>left</string> </dict> <key>markdown</key> <string>Wednesday, January 29, 2014n# Inspiration</string> </dict> Interpreting Objective-C. © Tim Burks. March 4, 2014
  32. 32. Interpreting Objective-C. © Tim Burks. March 4, 2014
  33. 33. Create Web Sites Interpreting Objective-C. © Tim Burks. March 4, 2014
  34. 34. (get "/radarid:"! (set radarnumber (radarid longLongValue))! (authenticate)! (set mongo (RadMongoDB new))! (mongo connect)! (set radar (mongo findOne:(dict number:radarnumber) inCollection:"openradar.radars"))! (if (and (radarid longLongValue) radar)! (then (set comments (mongo findArray:(dict $query:(dict radar_id:(radar _id:))! $orderby:(dict created:1))! inCollection:"openradar.comments"))! (htmlpage (+ "Radar " (radar number:))! (topbar)! (&div class:"row"! (&div class:"large-12 small-12 columns"! (panel-for-radar radar)))! (&div class:"row"! (&div class:"large-12 small-12 columns"! (&div class:"row"! (&div class:"large-2 medium-2 small-12 large-push-10 medium-push-10 columns" style:"text-align:right"! (if (eq (radar user:) screen_name)! (then (&a class:"button" href:(+ "/radars/edit/" (radar _id:)) "Edit"))! (else nil))! (field "Number" (radar number:))! (field "Originator" (mask-username (radar user:)))! (field "Date Originated" (radar originated:))! (field "Status" (radar status:))! (field "Resolved" (radar resolved:))! (field "Product" (radar product:))! (field "Product Version" (radar product_version:))! (field "Classification" (radar classification:))! (field "Reproducible" (radar reproducible:)))! (&div class:"large-10 large-pull-2 medium-10 medium-pull-2 small-12 columns" style:"padding:0 30px;"! (&p style:"white-space: pre-wrap; word-wrap: break-word; font-family:Courier, monospace; font-size:80%"! (if ((set description (radar description:)) length)! (then (escape (radar description:)))! (else (&em "No description provided."))))))! (&div class:"row"! (&div class:"large-10 medium-10 small-12 columns"! (&div class:"comments"! (comments map:! (do (comment)! (if (comment parent_id:)! (then "") ;; skip replies! (else (box-for-comment comment YES screen_name))))))))! (if screen_name! (then (&input id:"newcomment" type:"button" class:"button tiny" value:"Post a comment"))! (else (&p (&a href:"/signin" "Sign in") " to post comments and radars.")))! (&div style:"display:none;" id:"radar" (radar _id:))! (&br)! (&script type:"text/javascript" charset:"utf-8"! "if(jQuery("#error").text() == "") jQuery("#error").hide();")))))! (else nil)))! Interpreting Objective-C. © Tim Burks. March 4, 2014
  35. 35. http://programming.nu/posts/2013/04/14/Nu-2.1.0 Interpreting Objective-C. © Tim Burks. March 4, 2014
  36. 36. Interpreting Objective-C. © Tim Burks. March 4, 2014
  37. 37. Anywhere Objective-C is run Interpreting Objective-C. © Tim Burks. March 4, 2014
  38. 38. Usage Desire Craft Insight Interpreting Objective-C. © Tim Burks. March 4, 2014
  39. 39. MYNetwork objective-git UIKit Pantomime CocoaYAML NSURLRequest OTRKit MailCore SpriteKit SocketRocket NSKeyedArchiver google-api-objectivec-client PDFKit SSKeychain FMDB NSJSONSerialization CorePlot SSZipArchive PostgreSQL NSXPCConnection NSPropertyListSerialization PocketSVG AFNetworking MongoDB NSRegularExpression NSXMLDocument RestKit Xapian NSFileHandle MySQL NSSet PorterStemmer NSValue levelDB NSProcessInfo Simple-KML redis NSNumber SQLite NSDictionary libevent NSArray OpenGL libxml2 NSString NSURLSession AppKit Usage Desire Batteries Nuclear Power Included Craft http://programming.nu Insight Interpreting Objective-C. © Tim Burks. March 4, 2014

×