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
800
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
go directiveを最新にしすぎないで欲しい話──あるいは、Go 1.26からgo mod initで作られるgo directiveの値が変わる話 / Go 1.26 リリースパーティ
arthur1
2
470
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
1.7k
NOT A HOTEL - 建築や人と融合し、自由を創り出すソフトウェア
not_a_hokuts
2
570
オブザーバビリティ駆動開発って実際どうなの?
yohfee
3
690
手戻りゼロ? Spec Driven Developmentとは@KAG AI week
tmhirai
1
160
Agent Skills Workshop - AIへの頼み方を仕組み化する
gotalab555
14
7.9k
猫の手も借りたい!ので AIエージェント猫を作って社内に放した話 Claude Code × Container Lambda の Slack Bot "DevNeko"
naramomi7
0
250
AI主導でFastAPIのWebサービスを作るときに 人間が構造化すべき境界線
okajun35
0
550
RAGでハマりがちな"Excelの罠"を、データの構造化で突破する
harumiweb
9
2.5k
「やめとこ」がなくなった — 1月にZennを始めて22本書いた AI共創開発のリアル
atani14
0
350
20260228_JAWS_Beginner_Kansai
takuyay0ne
5
450
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
340
Featured
See All Featured
Optimizing for Happiness
mojombo
378
71k
GraphQLとの向き合い方2022年版
quramy
50
14k
Marketing to machines
jonoalderson
1
5k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
220
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.8k
Automating Front-end Workflow
addyosmani
1370
200k
Designing for humans not robots
tammielis
254
26k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
280
BBQ
matthewcrist
89
10k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
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?