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
670
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
730
俺のLTで俺のLTする
yoshiyasuko
1
500
Other Decks in Programming
See All in Programming
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
310
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
140
Ethereum_.pdf
nekomatu
0
460
現場で役立つモデリング 超入門
masuda220
PRO
15
3.2k
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
110
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
530
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
Click-free releases & the making of a CLI app
oheyadam
2
110
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Jakarta EE meets AI
ivargrimstad
0
580
RubyLSPのマルチバイト文字対応
notfounds
0
120
Realtime API 入門
riofujimon
0
150
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
A designer walks into a library…
pauljervisheath
203
24k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Code Review Best Practice
trishagee
64
17k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
A better future with KSS
kneath
238
17k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
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 ϒϩοΫʹείʔϓ͕ऩΊΒΕΔ
·ͱΊ
͔Ώ͍ॴʹ ख͕ಧ͍ͨκʂ
͡Ό ͦΏ͜ͱͰʙ