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
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
3
300
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
340
毎日13時間もかかるバッチ処理をたった3日で60%短縮するためにやったこと
sho_ssk_
1
160
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
1
140
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
160
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
340
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
780
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
5
720
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.7k
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
210
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
500
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Building Applications with DynamoDB
mza
91
6.1k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
A better future with KSS
kneath
238
17k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
520
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Site-Speed That Sticks
csswizardry
2
190
BBQ
matthewcrist
85
9.4k
Bash Introduction
62gerente
608
210k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Designing for humans not robots
tammielis
250
25k
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