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
クリーンアーキテクチャから見る依存の向きの大切さ
shimabox
5
1.1k
dbt Pythonモデルで実現するSnowflake活用術
trsnium
0
270
『テスト書いた方が開発が早いじゃん』を解き明かす #phpcon_nagoya
o0h
PRO
9
2.5k
複数のAWSアカウントから横断で 利用する Lambda Authorizer の作り方
tc3jp
0
120
DevNexus - Create AI Infused Java Apps with LangChain4j
kdubois
0
120
Honoをフロントエンドで使う 3つのやり方
yusukebe
7
3.6k
kintone開発を効率化するためにチームで試した施策とその結果を大放出!
oguemon
0
280
バッチを作らなきゃとなったときに考えること
irof
2
550
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
55
19k
Rubyと自由とAIと
yotii23
6
1.8k
Amazon Bedrockマルチエージェントコラボレーションを諦めてLangGraphに入門してみた
akihisaikeda
1
150
Datadog Workflow Automation で圧倒的価値提供
showwin
1
290
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
42
7.2k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
Making Projects Easy
brettharned
116
6k
Building an army of robots
kneath
303
45k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
How to train your dragon (web standard)
notwaldorf
91
5.9k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7.1k
Fireside Chat
paigeccino
35
3.2k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
Documentation Writing (for coders)
carmenintech
68
4.6k
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 ϒϩοΫʹείʔϓ͕ऩΊΒΕΔ
·ͱΊ
͔Ώ͍ॴʹ ख͕ಧ͍ͨκʂ
͡Ό ͦΏ͜ͱͰʙ