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
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.7k
Quine, Polyglot, 良いコード
qnighy
4
650
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
最新TCAキャッチアップ
0si43
0
190
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
flutterkaigi_2024.pdf
kyoheig3
0
150
Better Code Design in PHP
afilina
PRO
0
130
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
Featured
See All Featured
Docker and Python
trallard
40
3.1k
Speed Design
sergeychernyshev
25
620
What's new in Ruby 2.0
geeforr
343
31k
4 Signs Your Business is Dying
shpigford
180
21k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Being A Developer After 40
akosma
87
590k
Six Lessons from altMBA
skipperchong
27
3.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Faster Mobile Websites
deanohume
305
30k
Designing Experiences People Love
moore
138
23k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
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