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
Jack Nutting | let swift = Race?
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Swift Summit
March 22, 2015
Programming
2.7k
1
Share
Jack Nutting | let swift = Race?
Presented at
www.swiftsummit.com
Swift Summit
March 22, 2015
More Decks by Swift Summit
See All by Swift Summit
Marcin Krzyżanowski | CryptoSwift: Crypto You Can Do
swiftsummit
0
25k
Radek Pietruszewski | Swifty Methods
swiftsummit
2
7.6k
Gem Barrett | View from the Other Side
swiftsummit
0
1.6k
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
820
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
net-httpのHTTP/2対応について
naruse
0
380
AI駆動開発で崩れていくコードベースを立て直す
kyoko_nr_nr
1
400
TSKaigi2026-静的解析への投資がAI時代のコード品質を支える ── カスタムESLintルールの設計と運用
hayatokudou
7
1.3k
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.8k
Oxlintはいかにしてtsgolintのlint ruleを呼び出しているのか
syumai
2
1k
サーバーレスで作る、動画データ管理基盤
oyasumipants
0
320
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
140
Modding RubyKaigi for Myself
yui_knk
0
830
GitHub Copilot CLIのいいところ
htkym
2
1.2k
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
6
760
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
250
Stage 3 Decorators でできること / できないこと / TSKaigi 2026
susisu
1
1.4k
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
130
Mobile First: as difficult as doing things right
swwweet
225
10k
How to Ace a Technical Interview
jacobian
281
24k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
200
How to train your dragon (web standard)
notwaldorf
97
6.6k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Speed Design
sergeychernyshev
33
1.8k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Faster Mobile Websites
deanohume
310
31k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Transcript
let swift: Race? Jack Nutting @jacknutting
[email protected]
let swift: Race?
struct Sun { let swift: Race?
let strong: Battle? let wise: Bread? let intelligent: Riches? let knowledgeable: Favor? init() { swift = TimeAndChance() ? Race() : .None strong = TimeAndChance() ? Battle() : .None wise = TimeAndChance() ? Bread() : .None intelligent = TimeAndChance() ? Riches() : .None knowledgeable = TimeAndChance() ? Favor() : .None } }
let swift: Race?
None
[[somePeople like:ObjectiveC] evenIn:2015]
[[[[[[receiver method] method] method] method] method]
method]; receiver.method().method().method() .method().method().method()
Static fixed, stable, steady, consistent motionless, frozen, inert, lifeless
enum
enum Button { case Rectangular(bounds: CGRect,
title: String, font: UIFont) case RoundedCorners(bounds: CGRect, title: String, font: UIFont, radius: CGFloat) }
extension Button { func draw() {
switch self { case let .Rectangular(bounds, title, font): drawRectangleButton(bounds, title, font) case let .RoundedCorners(bounds, title, font, radius): drawRoundedRectangleButton(bounds, title, font, radius) } } }
extension Button { func buttonOfPreferredSize() -‐>
CGSize { switch self { case let .Rectangular(bounds, title, font): return preferredSizeForRectangleButton(bounds, title, font) case let .RoundedCorners(bounds, title, font, radius): return preferredSizeForRoundedRectangleButton(bounds, title, font, radius) } } }
• My Way or the Highway • Eternal Vigilance •
Boilerplate
If a huge chunk of your enum’s code is just
switching on the type, maybe you should just use a set of classes.
Using struct instead of class Marking classes as final Marking
methods as final
Future developers will want the flexibility to extend your system
in ways you can’t foresee.
–Sir Tony Hoare “Premature optimization is the root of all
evil.”
C++
–Jack Nutting “All of C++ is premature optimization.”
Functional Programming is not a silver bullet
http://chris.eidhof.nl/ posts/lenses-in-swift.html
https://www.destroyallsoftware.com/ talks/boundaries
Conclusions Sometimes enums aren’t the answer. Static has drawbacks. All
of C++ is premature optimization. FP is not a silver bullet.
Jack Nutting @jacknutting
[email protected]
let swift: Race?