Interpreting Objective C

39
Interpreting Objective-C @timburks

description

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.

Transcript of Interpreting Objective C

Page 1: Interpreting Objective C

Interpreting Objective-C@timburks

Page 2: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

“What’s new (nu)?”

ν

Page 3: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

“C over lambda.”

c/λ

Page 4: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Desire

InsightCraft

Usage

Page 5: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Desire

Page 6: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Beliefs about Better

Page 7: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

In any resource-constrained environment,

performance is everything.

1

Page 8: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

All environments of value are resource-constrained.

2

Page 9: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Performance is device performance and developer performance.

3

Page 10: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

The number of developers required to create a system

is its biggest weakness.

4

Page 11: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Stability and productivity are a developer's top two priorities,

in that order.

5

Page 12: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

• Simplicity allows speed. Speed increases opportunity.

• Simplicity allows control. Control reduces risk.

6

Page 13: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

• 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.

7

Page 14: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Insight

Page 15: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

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.

Page 16: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

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.

Page 17: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Craft

Page 18: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Parsing Nu

(puts (+ 2 2))!

2 2+

puts

NuCell

Nu_puts_operator

Nu_add_operator NSNumber NSNumber

NuCell

NuCell NuCellNuCell

Page 19: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Evaluating Nu

- (id) evaluateWithContext:(NSMutableDictionary *) context

2 2+

puts

NuCell

Nu_puts_operator

Nu_add_operator NSNumber NSNumber

NuCell

NuCell NuCellNuCell

Page 20: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Operators(+ 2 (/ 14 7)) !

!

Objects(UIStoryboard storyboardWithName:name bundle:nil) !

!

Page 21: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

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.

Page 22: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Interacting with the Runtime

The Nu class operator can be used to define new classes and to add methods to existing ones.

(class MyClass is NSObject ! (- hello is ! (puts “hello")))

Page 23: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

The Nu Shell

% nush!Nu Shell.!% (class MyClass is NSObject !- (- hello is (puts "hello")))!()!% (set myobject (MyClass new))!<MyClass:7fdb6863dd10>!% (myobject hello)!hello!()!

Page 24: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Usage

Page 25: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

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)!

Page 26: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

<?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>!

Page 27: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

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))

Page 28: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

{! 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;!}!

Page 29: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

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)! (if (eq x 4) (break))!

Page 30: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

[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)

Page 31: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

<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, 2014\n# Inspiration</string> </dict>

Build iOS apps

Page 32: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Page 33: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Create Web Sites

Page 34: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

(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)))!

Page 35: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

http://programming.nu/posts/2013/04/14/Nu-2.1.0

Page 36: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Page 37: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Anywhere Objective-C is run

Page 38: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Desire

InsightCraft

Usage

Page 39: Interpreting Objective C

Interpreting Objective-C. © Tim Burks. March 4, 2014

Desire

InsightCraft

Usage

Batteries Nuclear Power Includedhttp://programming.nu

PostgreSQL

MongoDB

MySQL

SQLite

NSURLSession

libevent

libxml2

AppKitUIKit

NSRegularExpression

NSXPCConnection

NSString

NSSet

NSDictionaryNSArray

MailCore

FMDBCorePlot

RestKit

NSValueNSNumber

NSURLRequest

NSPropertyListSerializationNSJSONSerialization

NSKeyedArchiver

NSProcessInfo

AFNetworking

SpriteKit

PDFKit

OpenGL

levelDB

Xapian

SSKeychainSSZipArchive

objective-git

NSXMLDocument

OTRKit

MYNetwork

SocketRocketCocoaYAMLPantomime

NSFileHandle

google-api-objectivec-client

PocketSVG

redis

PorterStemmer

Simple-KML