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
Kotlin 1.3 さらっとContracts + α
Search
Yoshiyasu KO
December 10, 2018
Programming
2
680
Kotlin 1.3 さらっとContracts + α
LINE Developers Meetup #47 in Fukuoka
Yoshiyasu KO
December 10, 2018
Tweet
Share
More Decks by Yoshiyasu KO
See All by Yoshiyasu KO
Groupieやってみよう
yoshiyasuko
0
760
俺のLTで俺のLTする
yoshiyasuko
1
510
Other Decks in Programming
See All in Programming
『GO』アプリ データ基盤のログ収集システムコスト削減
mot_techtalk
0
150
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
150
Jakarta EE meets AI
ivargrimstad
0
340
「個人開発マネタイズ大全」が教えてくれたこと
bani24884
1
160
技術を改善し続ける
gumioji
0
120
新宿駅構内を三人称視点で探索してみる
satoshi7190
2
120
生成AIで加速するテスト実装 - ロリポップ for Gamersの事例と 生成AIエディタの活用
kinosuke01
0
110
Amazon Q Developer Proで効率化するAPI開発入門
seike460
PRO
0
120
Ça bouge du côté des animations CSS !
goetter
2
150
GoとPHPのインターフェイスの違い
shimabox
2
210
Visual StudioのGitHub Copilotでいろいろやってみる
tomokusaba
1
210
コミュニティ駆動 AWS CDK ライブラリ「Open Constructs Library」 / community-cdk-library
gotok365
2
240
Featured
See All Featured
The Language of Interfaces
destraynor
156
24k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
640
Building a Scalable Design System with Sketch
lauravandoore
461
33k
Agile that works and the tools we love
rasmusluckow
328
21k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
10
1.3k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.4k
Faster Mobile Websites
deanohume
306
31k
Visualization
eitanlees
146
15k
KATA
mclloyd
29
14k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
12
990
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Transcript
Kotlin 1.3 ͞ΒͬͱContracts + α LINE Developers Meetup #47 in
Fukuoka @dashimaki_dofu
ϓϩϑΟʔϧ • ໊લ: ߴ Յହ (Yoshiyasu KO) • ॴଐ: ϕΨίʔϙϨʔγϣϯ
• AndroidΤϯδχΞ • : @dashimaki_dofu
ϓϩϑΟʔϧ ʮ͠ΜͪΌΜͷਓʯͱ֮͑ͯؼ͍ͬͯͩ͘͞ • ໊લ: ߴ Յହ (Yoshiyasu KO) • ॴଐ:
ϕΨίʔϙϨʔγϣϯ • AndroidΤϯδχΞ • : @dashimaki_dofu
What is Kotlin?
Kotlinʢ͜ͱΓΜʣ • 2013 JetBrains͕ࣾ։ൃͨ͠ ΦϒδΣΫτࢦܕݴޠ • JVM্Ͱಈ࡞ • Android Studio
3.0ΑΓ ެࣜαϙʔτ
2018.10.30 Kotlin 1.3ϦϦʔεʂ
Kotlin 1.3 • Coroutines ਖ਼ࣜ൛ • Kotlin/Native β൛ • Contracts
• when Ҿͷείʔϓ࠷దԽ etc...
Kotlin 1.3 • Coroutines ਖ਼ࣜ൛ • Kotlin/Native β൛ • Contracts
• when Ҿͷείʔϓ࠷దԽ etc... ࠓ͢ͷͪ͜Β
Contracts
Contracts = ܖ • ؔͷৼΔ͍Λʮܖʯ͢Δ • ίϯύΠϥʹؔͷৼΔ͍Λڭ͑Δ
?????
Smart Cast fun foo(s: String?) { if (s != null)
s.length }
Smart Cast fun foo(s: String?) { if (s != null)
s.length } T/VMMBCMF
Smart Cast fun foo(s: String?) { if (s != null)
s.length } /PU/VMMΛอূ
Smart Cast fun foo(s: String?) { if (s != null)
s.length } /PU/VMMΛอূ ͕ෆཁ
ྫ: isNullOrEmpty() fun foo(s: String?) { if (!s.isNullOrEmpty()) s!!.length }
~ Kotlin 1.2
ྫ: isNullOrEmpty() fun foo(s: String?) { if (!s.isNullOrEmpty()) s!!.length }
T͕ʮOVMMPSۭจࣈʯͰ͋ΕUSVF OVMMͰۭจࣈͰͳ͚ΕGBMTF GBMTFͰ͋Ε/PU/VMM͕อূ͞ΕΔͣ ~ Kotlin 1.2
ྫ: isNullOrEmpty() fun foo(s: String?) { if (!s.isNullOrEmpty()) s!!.length }
ίϯύΠϥJT/VMM0S&NQUZͷʮৼΔ͍ʯ͕͔Βͳ͍ 4NBSU$BTU͕ޮ͔ͳ͍ɾɾɾ ~ Kotlin 1.2
ྫ: isNullOrEmpty() fun foo(s: String?) { if (!s.isNullOrEmpty()) s.length }
Kotlin 1.3 JT/VMM0S&NQUZʹ࣮͞Εͨ$POUSBDUTʹΑͬͯ 4NBSU$BTU͕ޮ͘Α͏ʹͳΔʂ
ྫ: isNullOrEmpty() @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract
{ returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } Kotlin 1.3
ྫ: isNullOrEmpty() @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract
{ returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } Kotlin 1.3
ྫ: isNullOrEmpty() @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract
{ returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } %4- ޙड़ Ͱهड़͞ΕΔ Kotlin 1.3
ྫ: isNullOrEmpty() @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract
{ returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } GBMTFΛฦ࣌͢ Kotlin 1.3
ྫ: isNullOrEmpty() @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract
{ returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } GBMTFΛฦ࣌͢ /PU/VMMΛอূ͢Δ͜ͱΛ ܖ͢Δ Kotlin 1.3
ྫ: isNullOrEmpty() @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract
{ returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } GBMTFΛฦ࣌͢ /PU/VMMΛอূ͢Δ͜ͱΛ ܖ͢Δ ίϯύΠϥʹؔͷৼΔ͍Λ͑Δ͜ͱ͕Ͱ͖Δ Kotlin 1.3
Contracts DSL • returns() • ؔͷ࣮ߦʹޭͨ࣌͠ • returns(Boolean?) • ͕ؔҾͷΛฦͨ࣌͠
• returnsNotNull() • ͕ؔNotNullΛฦͨ࣌͠ • callsInPrace(block, InvocationKind) • block ͕ݺΕΔճΛ InvocationKind Ͱอূ͢Δ
Contracts DSL • returns() • ؔͷ࣮ߦʹޭͨ࣌͠ • returns(Boolean?) • ͕ؔҾͷΛฦͨ࣌͠
• returnsNotNull() • ͕ؔNotNullΛฦͨ࣌͠ • callsInPrace(block, InvocationKind) • block ͕ݺΕΔճΛ InvocationKind Ͱอূ͢Δ ࣗͰ$POUSBDUΛ࡞ΕΔ $VTUPN$POUSBDUT
when Ҿͷείʔϓ࠷దԽ
when Ҿͷείʔϓ࠷దԽ fun Request.getBody() { val response = executeRequest() return
when (response) { is Success -> response.body is HttpError -> throw HttpException(response.status) } } ~ Kotlin 1.2
when Ҿͷείʔϓ࠷దԽ fun Request.getBody() { val response = executeRequest() return
when (response) { is Success -> response.body is HttpError -> throw HttpException(response.status) } } ~ Kotlin 1.2 ϩʔΧϧมΛ͜͜Ͱ ఆٛ͢Δඞཁ͕͋Δ
when Ҿͷείʔϓ࠷దԽ fun Request.getBody() { val response = executeRequest() return
when (response) { is Success -> response.body is HttpError -> throw HttpException(response.status) } } ~ Kotlin 1.2 ϩʔΧϧมΛ͜͜Ͱ ఆٛ͢Δඞཁ͕͋Δ XIFO͚ͩͰ͏มͷείʔϓ͕͕ͬͯ͠·͏
when Ҿͷείʔϓ࠷దԽ fun Request.getBody() = when (val response = executeRequest())
{ is Success -> response.body is HttpError -> throw HttpException(response.status) } Kotlin 1.3
when Ҿͷείʔϓ࠷దԽ fun Request.getBody() = when (val response = executeRequest())
{ is Success -> response.body is HttpError -> throw HttpException(response.status) } Kotlin 1.3 ҾͰϩʔΧϧม͕ ఆٛͰ͖Δ
when Ҿͷείʔϓ࠷దԽ fun Request.getBody() = when (val response = executeRequest())
{ is Success -> response.body is HttpError -> throw HttpException(response.status) } Kotlin 1.3 ҾͰϩʔΧϧม͕ ఆٛͰ͖Δ ҾͰར༻͢ΔมͷείʔϓΛ XIFOϒϩοΫͰऩΊΔ͜ͱ͕Ͱ͖Δ \
ࠓͨ͜͠ͱ • Contract • ίϯύΠϥʹؔͷʮৼΔ͍ʯΛ͑Δ • ελϯμʔυϥΠϒϥϦʹΈࠐ·Ε͍ͯΔ • DSL Ͱهड़͞ΕΔ
• Custom Contracts ఆٛͰ͖Δ • when จͷҾͷείʔϓ࠷దԽ • ϩʔΧϧมΛҾͰఆٛͰ͖Δ • when ϒϩοΫʹείʔϓ͕ऩΊΒΕΔ
·ͱΊ
͔Ώ͍ॴʹ ख͕ಧ͍ͨκʂ
͡Ό ͦΏ͜ͱͰʙ