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
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
Click-free releases & the making of a CLI app
oheyadam
2
110
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
CSC509 Lecture 11
javiergs
PRO
0
180
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.5k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
890
Outline View in SwiftUI
1024jp
1
330
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
330
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
We Have a Design System, Now What?
morganepeng
50
7.2k
Teambox: Starting and Learning
jrom
133
8.8k
Documentation Writing (for coders)
carmenintech
65
4.4k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
KATA
mclloyd
29
14k
Typedesign – Prime Four
hannesfritz
40
2.4k
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