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.8k
住宅を WebXR で評価しよう / Evaluating My Home by WebXR
orgachem
PRO
0
72
HOME VR
orgachem
PRO
1
780
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
Vaporモードを大規模サービスに最速導入して学びを共有する
kazukishimamoto
4
4.3k
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
440
Synchronizationを支える技術
s_shimotori
1
150
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
210
Amazon Neptuneで始めてみるグラフDB-OpenSearchによるグラフの全文検索-
satoshi256kbyte
4
330
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.1k
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
210
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
340
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
1.3k
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
390
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
480
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
9
680
The Art of Programming - Codeland 2020
erikaheidi
51
13k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
Optimizing for Happiness
mojombo
376
69k
Building Adaptive Systems
keathley
38
2.2k
Building Your Own Lightsaber
phodgson
102
6k
Designing for Performance
lara
604
68k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
664
120k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Build The Right Thing And Hit Your Dates
maggiecrowley
32
2.4k
Rails Girls Zürich Keynote
gr2m
93
13k
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ͷ ճආྫΛࢀߟʹ͢ΔͱΑ͍Ͱ͠ΐ͏