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
Swift Summit
March 22, 2015
Programming
1
2.7k
Jack Nutting | let swift = Race?
Presented at
www.swiftsummit.com
Swift Summit
March 22, 2015
Tweet
Share
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.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 でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Realtime API 入門
riofujimon
0
150
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
役立つログに取り組もう
irof
28
9.6k
最新TCAキャッチアップ
0si43
0
190
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
みんなでプロポーザルを書いてみた
yuriko1211
0
280
cmp.Or に感動した
otakakot
3
200
Amazon Qを使ってIaCを触ろう!
maruto
0
410
Better Code Design in PHP
afilina
PRO
0
130
C++でシェーダを書く
fadis
6
4.1k
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
32
1.5k
It's Worth the Effort
3n
183
27k
Building Adaptive Systems
keathley
38
2.3k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Automating Front-end Workflow
addyosmani
1366
200k
Optimizing for Happiness
mojombo
376
70k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
A Tale of Four Properties
chriscoyier
156
23k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Done Done
chrislema
181
16k
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?