Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Radek Pietruszewski | Swifty Methods
Search
Swift Summit
March 22, 2015
Programming
2
7.6k
Radek Pietruszewski | Swifty Methods
Presented at
www.swiftsummit.com
Swift Summit
March 22, 2015
Tweet
Share
More Decks by Swift Summit
See All by Swift Summit
Jack Nutting | let swift = Race?
swiftsummit
1
2.7k
Marcin Krzyżanowski | CryptoSwift: Crypto You Can Do
swiftsummit
0
25k
Gem Barrett | View from the Other Side
swiftsummit
0
1.5k
Colin Eberhardt | ReactiveCocoa and Swift: Better Together
swiftsummit
3
14k
Joseph Lord | How Swift is Swift?
swiftsummit
2
31k
Al Skipp | The Monad Among Us
swiftsummit
3
770
Al Skipp | The Monad Among Us
swiftsummit
1
4.1k
Brian Gesiak | Swift API Design: Getting Results
swiftsummit
0
7.3k
Anthony Levings | JSON, Swift and Type Safety: It's a wrap
swiftsummit
2
19k
Other Decks in Programming
See All in Programming
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
Go の GC の不得意な部分を克服したい
taiyow
2
770
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
720
Haze - Real time background blurring
chrisbanes
1
510
ソフトウェアの振る舞いに着目し 複雑な要件の開発に立ち向かう
rickyban
0
890
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
270
return文におけるstd::moveについて
onihusube
1
1k
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
130
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
66
4.5k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Gamification - CAS2011
davidbonilla
80
5.1k
4 Signs Your Business is Dying
shpigford
181
21k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Unsuck your backbone
ammeep
669
57k
Rails Girls Zürich Keynote
gr2m
94
13k
Embracing the Ebb and Flow
colly
84
4.5k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
The Cost Of JavaScript in 2023
addyosmani
45
7k
Transcript
Radek
“Programs must be written for people to read, and only
incidentally for machines to execute” — Structure and Interpretation of Computer Programs
“Programs must be written for people to read, and only
incidentally for machines to execute”
Clarity
Clever is dumb
Clarity is worth it
None
clarity ≠ verbosity
naming things
naming things stringByReplacingOccurrencesOfString:withString:
naming things stringByReplacingOccurrencesOfString:withString: performSelectorOnMainThread:withObject:waitUntilDone:
naming things stringByReplacingOccurrencesOfString:withString: performSelectorOnMainThread:withObject:waitUntilDone: tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedI
[string componentsSeparatedByString:@"\n"];
[string componentsSeparatedByString:@"\n"]; huh?
[string componentsSeparatedByString:@"\n"]; huh? NSComponent?
[string componentsSeparatedByString:@"\n"]; 95% clear
[string componentsSeparatedByString:@"\n"]; 100% verbose 95% clear
string.split("\n")
string.split("\n") 95% clear
Adding more words doesn't help
What if you’re not sure?
None
split componentsSeparatedByString
Why save bytes?
clarity > brevity
brevity ⊂ clarity
Verbosity ain't free
Reading takes effort
clear > confusing short > verbose
Find the sweet spot
Remove the noise
split componentsSeparatedByString
replace stringByReplacingOccurencesOfString:withString:
stringByReplacingOccurencesOfString:withString:
stringByReplacingOccurencesOfString:withString:
replace
Remove the noise
let today : NSDate = NSDate()
let today = NSDate()
ty(activityType: "hash_state") rInfo = ["hash": hash] SURL(string: fallbackURL) omeCurrent() ity
= activity ; ; ; ; ;
ty(activityType: "hash_state") rInfo = ["hash": hash] SURL(string: fallbackURL) omeCurrent() ity
= activity
let array: [Int] = [10, 6, 2] array.reduce(0, { (acc:
Int, el: Int) -> Int in return acc + el })
let array = [10, 6, 2] array.reduce(0, +)
string1 string2 [ isEqualToString: ]
string1 string2
string1 == string2
if (foo && foo.bar) { foo.bar.baz() }
foo?.bar?.baz()
less code to understand is a good thing
[[NSWindow alloc] initWithContentRect: frame styleMask: NSTitledWindowMask backing: NSBackingStoreBuffered defer: NO
screen: nil]
[[NSWindow alloc] initWithContentRect: frame styleMask: NSTitledWindowMask backing: NSBackingStoreBuffered defer: NO
screen: nil]
init( contentRect: NSRect, styleMask: NSWindowMask = .Titled, backing: NSBackingStoreType =
.Buffered, defer: Bool = false, screen: NSScreen? = nil)
[[NSWindow alloc] initWithContentRect: frame styleMask: NSTitledWindowMask backing: NSBackingStoreBuffered defer: NO
screen: nil]
NSWindow(contentRect: frame)
Swifty APIs
[NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector(foo:) userInfo: nil repeats:
YES] . . . - (void) foo: (NSTimer *timer) { NSLog(@“Hello world!”) } radex.io/swift/nstimer
[NSTimer scheduledTimerWithTimeInterval:1.0] radex.io/swift/nstimer
[NSTimer scheduledTimerWithTimeInterval:1.0] radex.io/swift/nstimer
[NSTimer scheduledTimerWithTimeInterval:1.0] radex.io/swift/nstimer
[NSTimer scheduledTimerWithTimeInterval:1.0] radex.io/swift/nstimer
NSTimer.schedule(interval: 1.0) radex.io/swift/nstimer
NSTimer.schedule(interval: 1.0, target: self, selector: "foo:", userInfo: nil, repeats: true)
func foo(timer: NSTimer) { println("Hello world") } radex.io/swift/nstimer
NSTimer.schedule(interval: 1.0, userInfo: nil, repeats: true) { println("Hello world") }
radex.io/swift/nstimer
NSTimer.schedule(interval: 1.0, repeats: true) { println("Hello world") } radex.io/swift/nstimer
NSTimer.schedule(every: 1.0) { println("Hello world") } radex.io/swift/nstimer
NSTimer.schedule(every: 1.second) { println("Hello world") } radex.io/swift/nstimer
NSTimer.schedule(after: 1.second) { println("Hello world") } radex.io/swift/nstimer
[NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector(foo:) userInfo: nil repeats:
YES] . . . - (void) foo: (NSTimer *timer) { NSLog(@“Hello world!”) } radex.io/swift/nstimer
NSTimer.schedule(every: 1.second) { println("Hello world") } radex.io/swift/nstimer
Recap: 4 ideas
Focus on clarity
Don't write clever code
clarity ≠ verbosity
None
radex.io/swift/methods @radexp