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
React 19アップデートのために必要なこと
uhyo
8
1.5k
Django NinjaによるAPI開発の効率化とリプレースの実践
kashewnuts
1
260
Kotlinの開発でも AIをいい感じに使いたい / Making the Most of AI in Kotlin Development
kohii00
5
1.3k
第3回関東Kaggler会_AtCoderはKaggleの役に立つ
chettub
3
1.2k
ナレッジイネイブリングにAIを活用してみる ゆるSRE勉強会 #9
nealle
0
160
DRFを少しずつ オニオンアーキテクチャに寄せていく DjangoCongress JP 2025
nealle
2
270
ファインディLT_ポケモン対戦の定量的分析
fufufukakaka
0
920
Rails アプリ地図考 Flush Cut
makicamel
1
130
15分で学ぶDuckDBの可愛い使い方 DuckDBの最近の更新
notrogue
3
520
Visual StudioのGitHub Copilotでいろいろやってみる
tomokusaba
1
210
SwiftUI Viewの責務分離
elmetal
PRO
2
270
Learning Kotlin with detekt
inouehi
1
140
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
80
8.9k
We Have a Design System, Now What?
morganepeng
51
7.4k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
KATA
mclloyd
29
14k
Building an army of robots
kneath
303
45k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Documentation Writing (for coders)
carmenintech
67
4.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
114
50k
Statistics for Hackers
jakevdp
797
220k
Building Your Own Lightsaber
phodgson
104
6.2k
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 ϒϩοΫʹείʔϓ͕ऩΊΒΕΔ
·ͱΊ
͔Ώ͍ॴʹ ख͕ಧ͍ͨκʂ
͡Ό ͦΏ͜ͱͰʙ