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
650
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
650
俺のLTで俺のLTする
yoshiyasuko
1
440
Other Decks in Programming
See All in Programming
データアナリストが行うDatabricksを活用したETLの自動化事例
shinoa
0
270
検証も兼ねて個人開発でHonoとかと向き合った話
hanetsuki
1
910
Komplexe Oberflächen mit SVG und der Web Animation API
joergneumann
0
670
CA.swift19 恋するAIアプリ開発の裏側
oskmr
0
360
ゆるい個人開発のススメ
kuroppe1819
10
990
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
270
Milestoner
bkuhlmann
1
410
ONE WEDGE_company_guide
1wedge_one
0
470
Rubyでたのしむクリエイティブコーディング/Enjoy Creative coding with Ruby
chobishiba
1
180
今、知っておきたい! 生成AIエージェントの世界
elith
3
360
Fragment Composition of GraphQL
quramy
6
950
デフォルトにして至高、RubyMineの大好きな所
ruzia
0
360
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
260
12k
Bootstrapping a Software Product
garrettdimon
PRO
302
110k
WebSockets: Embracing the real-time Web
robhawkes
59
7k
The MySQL Ecosystem @ GitHub 2015
samlambert
243
12k
4 Signs Your Business is Dying
shpigford
175
21k
Optimising Largest Contentful Paint
csswizardry
8
2.4k
How GitHub (no longer) Works
holman
304
140k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
14
1.6k
Building Effective Engineering Teams - LeadDev
addyosmani
28
1.8k
What the flash - Photography Introduction
edds
64
11k
Building Flexible Design Systems
yeseniaperezcruz
319
37k
The Language of Interfaces
destraynor
151
23k
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 ϒϩοΫʹείʔϓ͕ऩΊΒΕΔ
·ͱΊ
͔Ώ͍ॴʹ ख͕ಧ͍ͨκʂ
͡Ό ͦΏ͜ͱͰʙ