Slide 1

Slide 1 text

Radek

Slide 2

Slide 2 text

“Programs must be written for people to read, and only incidentally for machines to execute” — Structure and Interpretation of Computer Programs

Slide 3

Slide 3 text

“Programs must be written for people to read, and only incidentally for machines to execute”

Slide 4

Slide 4 text

Clarity

Slide 5

Slide 5 text

Clever is dumb

Slide 6

Slide 6 text

Clarity is worth it

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

clarity ≠ verbosity

Slide 9

Slide 9 text

naming things

Slide 10

Slide 10 text

naming things stringByReplacingOccurrencesOfString:withString:

Slide 11

Slide 11 text

naming things stringByReplacingOccurrencesOfString:withString: performSelectorOnMainThread:withObject:waitUntilDone:

Slide 12

Slide 12 text

naming things stringByReplacingOccurrencesOfString:withString: performSelectorOnMainThread:withObject:waitUntilDone: tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedI

Slide 13

Slide 13 text

[string componentsSeparatedByString:@"\n"];

Slide 14

Slide 14 text

[string componentsSeparatedByString:@"\n"]; huh?

Slide 15

Slide 15 text

[string componentsSeparatedByString:@"\n"]; huh? NSComponent?

Slide 16

Slide 16 text

[string componentsSeparatedByString:@"\n"]; 95% clear

Slide 17

Slide 17 text

[string componentsSeparatedByString:@"\n"]; 100% verbose 95% clear

Slide 18

Slide 18 text

string.split("\n")

Slide 19

Slide 19 text

string.split("\n") 95% clear

Slide 20

Slide 20 text

Adding more words doesn't help

Slide 21

Slide 21 text

What if you’re not sure?

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

split componentsSeparatedByString

Slide 24

Slide 24 text

Why save bytes?

Slide 25

Slide 25 text

clarity > brevity

Slide 26

Slide 26 text

brevity ⊂ clarity

Slide 27

Slide 27 text

Verbosity ain't free

Slide 28

Slide 28 text

Reading takes effort

Slide 29

Slide 29 text

clear > confusing short > verbose

Slide 30

Slide 30 text

Find the sweet spot

Slide 31

Slide 31 text

Remove the noise

Slide 32

Slide 32 text

split componentsSeparatedByString

Slide 33

Slide 33 text

replace stringByReplacingOccurencesOfString:withString:

Slide 34

Slide 34 text

stringByReplacingOccurencesOfString:withString:

Slide 35

Slide 35 text

stringByReplacingOccurencesOfString:withString:

Slide 36

Slide 36 text

replace

Slide 37

Slide 37 text

Remove the noise

Slide 38

Slide 38 text

let today : NSDate = NSDate()

Slide 39

Slide 39 text

let today = NSDate()

Slide 40

Slide 40 text

ty(activityType: "hash_state") rInfo = ["hash": hash] SURL(string: fallbackURL) omeCurrent() ity = activity ; ; ; ; ;

Slide 41

Slide 41 text

ty(activityType: "hash_state") rInfo = ["hash": hash] SURL(string: fallbackURL) omeCurrent() ity = activity

Slide 42

Slide 42 text

let array: [Int] = [10, 6, 2] array.reduce(0, { (acc: Int, el: Int) -> Int in return acc + el })

Slide 43

Slide 43 text

let array = [10, 6, 2] array.reduce(0, +)

Slide 44

Slide 44 text

string1 string2 [ isEqualToString: ]

Slide 45

Slide 45 text

string1 string2

Slide 46

Slide 46 text

string1 == string2

Slide 47

Slide 47 text

if (foo && foo.bar) { foo.bar.baz() }

Slide 48

Slide 48 text

foo?.bar?.baz()

Slide 49

Slide 49 text

less code to understand is a good thing

Slide 50

Slide 50 text

[[NSWindow alloc] initWithContentRect: frame styleMask: NSTitledWindowMask backing: NSBackingStoreBuffered defer: NO screen: nil]

Slide 51

Slide 51 text

[[NSWindow alloc] initWithContentRect: frame styleMask: NSTitledWindowMask backing: NSBackingStoreBuffered defer: NO screen: nil]

Slide 52

Slide 52 text

init( contentRect: NSRect, styleMask: NSWindowMask = .Titled, backing: NSBackingStoreType = .Buffered, defer: Bool = false, screen: NSScreen? = nil)

Slide 53

Slide 53 text

[[NSWindow alloc] initWithContentRect: frame styleMask: NSTitledWindowMask backing: NSBackingStoreBuffered defer: NO screen: nil]

Slide 54

Slide 54 text

NSWindow(contentRect: frame)

Slide 55

Slide 55 text

Swifty APIs

Slide 56

Slide 56 text

[NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector(foo:) userInfo: nil repeats: YES] . . . - (void) foo: (NSTimer *timer) { NSLog(@“Hello world!”) } radex.io/swift/nstimer

Slide 57

Slide 57 text

[NSTimer scheduledTimerWithTimeInterval:1.0] radex.io/swift/nstimer

Slide 58

Slide 58 text

[NSTimer scheduledTimerWithTimeInterval:1.0] radex.io/swift/nstimer

Slide 59

Slide 59 text

[NSTimer scheduledTimerWithTimeInterval:1.0] radex.io/swift/nstimer

Slide 60

Slide 60 text

[NSTimer scheduledTimerWithTimeInterval:1.0] radex.io/swift/nstimer

Slide 61

Slide 61 text

NSTimer.schedule(interval: 1.0) radex.io/swift/nstimer

Slide 62

Slide 62 text

NSTimer.schedule(interval: 1.0, target: self, selector: "foo:", userInfo: nil, repeats: true) func foo(timer: NSTimer) { println("Hello world") } radex.io/swift/nstimer

Slide 63

Slide 63 text

NSTimer.schedule(interval: 1.0, userInfo: nil, repeats: true) { println("Hello world") } radex.io/swift/nstimer

Slide 64

Slide 64 text

NSTimer.schedule(interval: 1.0, repeats: true) { println("Hello world") } radex.io/swift/nstimer

Slide 65

Slide 65 text

NSTimer.schedule(every: 1.0) { println("Hello world") } radex.io/swift/nstimer

Slide 66

Slide 66 text

NSTimer.schedule(every: 1.second) { println("Hello world") } radex.io/swift/nstimer

Slide 67

Slide 67 text

NSTimer.schedule(after: 1.second) { println("Hello world") } radex.io/swift/nstimer

Slide 68

Slide 68 text

[NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector(foo:) userInfo: nil repeats: YES] . . . - (void) foo: (NSTimer *timer) { NSLog(@“Hello world!”) } radex.io/swift/nstimer

Slide 69

Slide 69 text

NSTimer.schedule(every: 1.second) { println("Hello world") } radex.io/swift/nstimer

Slide 70

Slide 70 text

Recap: 4 ideas

Slide 71

Slide 71 text

Focus on clarity

Slide 72

Slide 72 text

Don't write clever code

Slide 73

Slide 73 text

clarity ≠ verbosity

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

radex.io/swift/methods @radexp