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
構造的差分ライブラリ開発時の悲劇・喜劇
Search
Kuniwak
PRO
October 13, 2017
Programming
7
2.9k
構造的差分ライブラリ開発時の悲劇・喜劇
https://iosdc-reject-conference.connpass.com/event/64175/
Kuniwak
PRO
October 13, 2017
Tweet
Share
More Decks by Kuniwak
See All by Kuniwak
欠陥を早期に発見するための Software Engineer in Test とその重要性 / What is Software Engineer in Test and How they works
orgachem
PRO
21
3.9k
住宅を WebXR で評価しよう / Evaluating My Home by WebXR
orgachem
PRO
0
77
HOME VR
orgachem
PRO
1
790
uGUI の自動操作の考え方と操作方法
orgachem
PRO
1
1.3k
Swift Macro に備えて構文木を 10min で学ぶ / Learn Syntax Tree for Swift Macro in 10 minutes
orgachem
PRO
1
1.1k
SoftWare Engineer in Test のおしごと / What is SWET
orgachem
PRO
1
1k
私と Nature Remo E / Nature Remo E
orgachem
PRO
0
25k
存在しないアセットへの参照と 未公開アセットでのネタバレに どう立ち向かうか / How to prevent missing assets and spoilers by assets
orgachem
PRO
1
1k
睡眠する技術 / Technology to Sleep
orgachem
PRO
15
14k
Other Decks in Programming
See All in Programming
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.3k
Better Code Design in PHP
afilina
PRO
0
130
subpath importsで始めるモック生活
10tera
0
320
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
Modular Monolith Monorepo ~シンプルさを保ちながらmonorepoのメリットを最大化する~
yuisakamoto
5
330
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
カンファレンスの「アレ」Webでなんとかしませんか? / Conference “thing” Why don't you do something about it on the Web?
dero1to
1
110
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
flutterkaigi_2024.pdf
kyoheig3
0
150
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.8k
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
710
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
88
5.7k
Building Your Own Lightsaber
phodgson
103
6.1k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
110
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
KATA
mclloyd
29
14k
Writing Fast Ruby
sferik
627
61k
Into the Great Unknown - MozCon
thekraken
32
1.5k
Designing for Performance
lara
604
68k
Scaling GitHub
holman
458
140k
Transcript
ߏతࠩϥΠϒϥϦ ։ൃ࣌ͷ൵ܶتܶ σόοάΛॿ͚Δ
ߏతͳࠩͱԿ͔ ·ͣ
func testExample1() { let a = Example( key1: "I'm not
changed", key2: "I'm deleted" ) let b = Example( key1: "I'm not changed", key2: "I'm inserted" ) XCTAssertEqual(a, b) } Α͋͘ΔTUSVDUͷൺֱ
XCTAssertEqual failed: ("Example(key1: "I\'m not changed", key2: "I\'m deleted")") is
not equal to ("Example(key1: "I\'m not changed", key2: "I\'m inserted")") - ςετ݁ՌඇৗʹΘ͔ΓͮΒ͍
IUUQHJUIVCDPN,VOJXBL.JSSPS%J⒎,JU ͦ͜Ͱ
import MirrorDiffKit func testExample2() { let a = Example( key1:
"I'm not changed", key2: "I'm deleted" ) let b = Example( key1: "I'm not changed", key2: "I'm inserted" ) XCTAssertEqual(a, b, diff(between: a, and: b)) } ࣦഊ࣌ͷϝοηʔδʹ .JSSPS%J⒎,JUͷEJ⒎Λࢦఆ .JSSPS%J⒎,JUΛJNQPSU
struct Example { key1: "I'm not changed" - key2: "I'm
deleted" + key2: "I'm inserted" } ͜Ε͕ߏతͳࠩ ͙͢ʹࠩҟ͕Θ͔Γ·͢
[ "I'm not changed" "I'm not changed" - "I'm deleted"
"I'm not changed" + "I'm inserted" ] ྻͷॱংมߋͳͲ ߏతͳࠩͰ͢ ͜Εݟ͘͢දࣔ͞Ε·͢
IUUQHJUIVCDPN,VOJXBL.JSSPS%J⒎,JU ΑΖ͓͘͠ئ͍͠·͢
Έͷղઆ ࠩܭࢉͷ
let example = Example( key1: "I'm not changed", key2: "I'm
deleted" ) let hint = ( subject: Example.self, displayStyle: .struct, children: [ (label: "key1", value: "I'm not changed"), (label: "key2", value: "I'm deleted"), ] ) ߏతͳࠩͷܭࢉʹɺ ࣍ͷΑ͏ͳΦϒδΣΫτͷ ߏͷώϯτ͕ෆՄܽͰ͢ ΦϒδΣΫτͷܕ ΦϒδΣΫτͷछྨ ϓϩύςΟͷ໊લͱ
ͦͷػೳΛ୲͏ͷ͕.JSSPS ʢඪ४ϥΠϒϥϦͷ"1*Ͱ͢ʣ
let example = Example( key1: "I'm not changed", key2: "I'm
deleted" ) let mirror = Mirror(reflecting: example) let hint = ( subject: mirror.subjectType, displayStyle: mirror.displayStyle, children: mirror.children ) ௐ͍ͨΦϒδΣΫτ͔Β .JSSPSΦϒδΣΫτΛ ࡞͢Δͱɺ ܕใΦϒδΣΫτͷछྨɺ ϓϩύςΟͷ໊લͱͳͲΛ ೖखͰ͖·͢
.JSSPS%J⒎,JUɺ ͜ͷ.JSSPSΛͬͯ ࣮ݱ͞Ε͍ͯ·͢
͍ΖΜͳ͜ͱ͕Ͱ͖ͦ͏Ͱ ເͷ͕Δ"1*Ͱ͢Ͷ
تܶ͜͜·Ͱͩ
͍OJM͕͍ ൵ܶͦͷ
struct Example { let any: Any? } let example =
Example(any: nil) if let first = Mirror(reflecting: example) .children.first { print(first.value) } ϓϩύςΟΛOJMͰॳظԽ ϓϩύςΟͷΛݟΔͱɺ ઌ΄ͲOJMͰॳظԽͨ͠ͷͰ OJMʹͳ͍ͬͯΔ "OZ ͷϓϩύςΟ͕͋ΔTUSVDU .JSSPSΛ࡞ͯ͠ɺTUSVDUͷ ϓϩύςΟͷώϯτΛೖख
struct Example { let any: Any? } let example =
Example(any: nil) if let first = Mirror(reflecting: example) .children.first { print(first.value == nil) print(first.value) } GBMTF OJMͰ͔֬ΊͯΈΑ͏ ͔͠͠ೖ͍ͬͯΔͷOJMʜ
ߟฤ ൵͠Έͷ
"OZʹ ͳΜͰೖΔ ᶃ Int String Bool Any
0QUJPOBM ೖΕΒΕΔ ᶄ Optional<T> Any
͢ΔͱOJM ೖΓ͏Δ ᶄ nil Any
ᶄ nil Any == nil GBMTF
let x: Any? = nil let wrapper: Any = x
// WARNING: Comparing non-optional value of // type 'Any' to nil always returns false print(x == nil) ࣮ղઆͨ͠ྫΛίʔυʹ͢Δͱܯࠂ͕ग़Δ ʮ0QUJPOBM͡Όͳ͍ͱOJMΛ ɹൺֱͯ͠ৗʹGBMTFͩΑʯ
ͭ·Γɺ"OZʹOJMΛ ೖΕͯͳΒͳ͍ͷͰ͢
͔͠͠ɺ.JSSPSͰऔಘͨ͠ ϓϩύςΟͷͷܕ ແ༻Ͱ"OZͱ͍͏൵͠Έ ͳͷͰɺϓϩύςΟʹOJMΛͭ ΦϒδΣΫτΛ.JSSPSʹ͔͚Δͱ Ϋϥογϡͷةݥ͕͋Γ·͢
.JSSPS%J⒎,JUͰ͜ͷʹ ରॲ͍ͯ͠·͢ͷͰ҆͝৺Λʜ
ཁૉͷUVQMF ൵ܶͦͷ
enum Example { case zero case one(key: String) case two(key1:
String, key2: String) } 4XJGUͰFOVNͷDBTFʹଐ͢ΔΛఆٛͰ͖·͢ ͜ͷଐ͢ΔBTTPDJBUFEWBMVFTͱݺΕ͍ͯ·͢
enum Example { case one(key: String) case two(key1: String, key2:
String) } func test() { let x1: Example = .one(key: "value") let x2: Example = .two(key1: "value1", key2: "value2") let mirror1 = Mirror(reflecting: x1) let mirror2 = Mirror(reflecting: x2) dump(mirror1.children.first!.value) dump(mirror2.children.first!.value) } ͦΕͧΕΛ.JSSPSʹ͔͚·͢ ͜͜ͰBTTPDJBUFEWBMVFTͷ ཁૉ͕ҟͳΔͭͷDBTFΛ ఆٛ͠·͢ BTTPDJBUFWBMVFTɺ TUSVDUͷϓϩύςΟͱ ಉ͡Α͏ʹDIJMESFOͰ දݱ͞Ε·͢ ͦΕͧΕͷDIJMESFOΛ ֬ೝͯ͠Έ·͠ΐ͏
enum Example { case one(key: String) case two(key1: String, key2:
String) } func test() { let x1: Example = .one(key: "value") let x2: Example = .two(key1: "value1", key2: "value2") let mirror1 = Mirror(reflecting: x1) let mirror2 = Mirror(reflecting: x2) dump(mirror1.children.first!.value) dump(mirror2.children.first!.value) } BTTPDJBUFEWBMVFT͕ ͭͷ߹ WBMVF ͭͷ߹ LFZWBMVF LFZWBMVF ܕ͕ҧ͏
ߟฤ ൵͠Έͷ
let y: Any = (number: 123) print(type(of: y)) ܕΛௐͯΈΔͱ
*OU ຊBTTPDJBUFEWBMVFTͷཁૉ͕ ͍ͭ͘Ͱ͋ΕɺDIJMESFOͷܕUVQMFʹ ͔ͨͬͨ͠ͷͰͱਪଌ ͔͠͠ɺཁૉͷ͚࣌ͩࣄ͕͋ͬͯ UVQMFʹͰ͖ͳ͔͔ͬͨ͠Εͳ͍ͷͰɺ ࢼ͠ʹཁૉ͕ͭͷUVQMFΛ࡞ͯ͠ΈΔ UVQMFͰͳ͍
// Error: cannot create a single-element tuple with // an
element label let x: (number: Int) = (number: 123) let y: Any = (number: 123) print(type(of: y)) // Int ࣮ɺ4XJGUͷܕͰཁૉ͕ͭͷUVQMFఆٛͰ͖ͳ͍ ͔͠͠ɺཁૉͷUVQMFܕ͕ ࡞Εͳ͍͚ͩͳͷͰɺܕΛ "OZʹͯ͠͠·͑ཁૉͷ UVQMFΒ͖͠ͷΛఆٛͰ͖Δ ͔͠͠ɺఆٛͰ͖ͨͱͯ͠ɺ ͦͷܕཁૉͷதͷܕʹ ͳΔΑ͏ͩ ͭ·ΓɺཁૉͷUVQMF ଘࡏͰ͖ͳ͍͜ͱ͕Θ͔Δ
ཁૉͷUVQMFܕଘࡏͰ͖ͳ͍ͷͰɺ ຊདྷUVQMFͰ͋Δͣͷ BTTPDJBUFEWBMVFT͕ɺཁૉͷ ͱ͖ʹத͚ͩʹͳΔͷͰͨ͠ʜ
.JSSPS%J⒎,JUͰ͜ͷʹ ରॲ͍ͯ͠·͢ͷͰ҆͝৺Λʜ
ΧδϡΞϧʹյΕΔ ൵ܶͦͷ
·ͱΊ w .JSSPSͱ͍͏TUSVDUͳͲͷߏΛ ௐΔͨΊͷ"1*͕͋Γ·͢ w ৭ʑͰ͖ͦ͏Ͱເ͕͕Γ·͢ w ͔͠͠ɺ͔ͳΓͷͭΒΈ͕͋Γ·͢ͷͰ ͍ͬͯ͘ࡍʹ.JSSPS%J⒎,JUͷ ճආྫΛࢀߟʹ͢ΔͱΑ͍Ͱ͠ΐ͏