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
Kolin Modifiers
Search
kissybnts
June 26, 2017
Programming
2
260
Kolin Modifiers
「KotlinのLT会!Kotlin入門者の集い」で発表したやつの全部込み版です。
kissybnts
June 26, 2017
Tweet
Share
More Decks by kissybnts
See All by kissybnts
JavaエンジニアからみたVapor
kissybnts
0
180
Other Decks in Programming
See All in Programming
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
290
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
130
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
260
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
760
Go の GC の不得意な部分を克服したい
taiyow
3
780
Beyond ORM
77web
5
660
Jakarta EE meets AI
ivargrimstad
0
240
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
Haze - Real time background blurring
chrisbanes
1
510
良いユニットテストを書こう
mototakatsu
7
2.2k
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
110
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
For a Future-Friendly Web
brad_frost
175
9.4k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Unsuck your backbone
ammeep
669
57k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Agile that works and the tools we love
rasmusluckow
328
21k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Done Done
chrislema
181
16k
Transcript
Kolin Modifiers ,PUMJOͷ-5ձʂ,PUMJOೖऀͷू͍
Name: Company: Role: Language: Kotlin: ͖ͩ͠ ServerSideEngineer, BridgeEngineer Java 1.0͘Β͍͔Β
None
None
,PUMJOʹؔʹ͚ͭΔ͜ͱ͕Ͱ͖Δ .PEJpFS म০ࢠ ͕͍Ζ͍Ζ͋Δ
‣ infix ‣ inline ‣ noinline ‣ crossinline ‣ reified
‣ tailrec
͜ΕΒΛઆ໌͠·͢
7JTJCJMJUZ.PEJpFSTάά͍ͬͯͩ͘͞
infix
Ҿ͕ͭͷϝιουΛ ׅހͳ͠Ͱ͑ΔΑ͏ʹ͢Δ
None
infix Modifier
StringΫϥεͷ֦ுؔ
ҾҰͭ
͜Μͳ෩ʹ͑Δ
w ϝϯόؔ·֦ͨுؔ w Ҿ͕ͭ w infixΛؔʹ͚ͭΔ ༻݅
ͪΖΜͭͳ͛ͯ͑Δ
͜ΕΛ
͜͏ͯ͠
͜ΕΛ
͜͏͢Δ
ͪͳΈʹ
͜ΕͩΊ
͜Ε0,
inline
'VODUJPOMJUFSBMΛΠϯϥΠϯల։͢Δ͜ͱͰ ࣮ߦ࣌ͷΦʔόʔϔουΛݮΒ͠ ύϑΥʔϚϯεΛ্ͤ͞Δ
None
'VODUJPOMJUFSBMΛΠϯϥΠϯల։͢Δ͜ͱͰ ࣮ߦ࣌ͷΦʔόʔϔουΛݮΒ͠ ύϑΥʔϚϯεΛ্ͤ͞Δ
'VODUJPOMJUFSBMΛΠϯϥΠϯల։͢Δ͜ͱͰ ࣮ߦ࣌ͷΦʔόʔϔουΛݮΒ͠ ύϑΥʔϚϯεΛ্ͤ͞Δ
'VODUJPOMJUFSBMͱʁ
None
ແ໊ؔ
ϥϜμࣜͰ͞ΕΔ ؔͷ͜ͱ
ΠϯϥΠϯల։ͱʁ
؆୯ͳൺֱͰઆ໌
None
StringΫϥεͷ֦ுؔ
StringΛҾʹͱͬͯStringΛฦؔ͢
ҾͷؔΛ࣮ߦͯ͠ɺtoUpperCase()ͯ͠ฦ͢
inline Modifier
ͦΕҎ֎Ұॹ
None
݁Ռಉ͡
None
ͦΕͧΕ࣮ߦ࣌ʹͲ͏ͳΔͷ͔ʁ
inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠આ໌͠·͢ */
inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
SFDFJWFSͷΛ֨ೲ inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
֦ுؔͱಉ໊͡લͷ͕ؔ࡞͞ΕݺΕΔ inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
ୈҰҾʹSFDFJWFS inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
ؔΦϒδΣΫτͷΠϯελϯεΛ࡞ׂͯ͠Γͯ inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
/* આ໌ͷͨΊʹ؆ུతʹهड़ͨ͠ΫϥεͰ͢ */ inlineແ͠
JOWPLFͱ͍͏ϝιουΛͭ /* આ໌ͷͨΊʹ؆ུతʹهड़ͨ͠ΫϥεͰ͢ */ inlineແ͠
தϥϜμࣜͰͨ͠ॲཧ /* આ໌ͷͨΊʹ؆ུతʹهड़ͨ͠ΫϥεͰ͢ */ inlineແ͠
/* આ໌ͷͨΊʹ؆ུతʹهड़ͨؔ͠Ͱ͢ */ inlineແ͠
ϥϜμࣜͰͨ͠ॲཧΛͭΠϯελϯε /* આ໌ͷͨΊʹ؆ུతʹهड़ͨؔ͠Ͱ͢ */ inlineແ͠
ϥϜμࣜͰͨ͠ॲཧΛ࣮ߦ /* આ໌ͷͨΊʹ؆ུతʹهड़ͨؔ͠Ͱ͢ */ inlineແ͠
toUpperCase()Λͯ͠ฦ͢ /* આ໌ͷͨΊʹ؆ུతʹهड़ͨؔ͠Ͱ͢ */ inlineແ͠
inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
ϝιουݺͼग़͠ͷίετ inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
Πϯελϯεੜͷίετ inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
None
/* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠આ໌͠·͢ */ inline͋Γ
inline͋Γ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
ಉ͡ inline͋Γ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
ϥϜμࣜͰͨ͠ॲཧ inline͋Γ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
toUpperCase()ͯ͠ऴΘΓ inline͋Γ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
ΠϯϥΠϯల։ inline͋Γ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
'VODUJPOMJUFSBMΛΠϯϥΠϯల։͢Δ͜ͱͰ ࣮ߦ࣌ͷΦʔόʔϔουΛݮΒ͠ ύϑΥʔϚϯεΛ্ͤ͞Δ
Πϯελϯεͷੜίετ ϝιουݺͼग़͠ͷίετ
Πϯελϯεͷੜίετ ϝιουݺͼग़͠ͷίετ
None
ؔ࿈͢Δಛ
ϥϜμࣜͷதͰreturnΛͬͯ ݺͼग़͠ݩͷؔΛൈ͚Δ͜ͱ͕Ͱ͖Δ
inlineͳ͠
None
ίϯύΠϧΤϥʔ
͜ͷதͰݺͼग़͠ݩͷ͔ؔΒൈ͚Α͏ͱ͢Δ
inline͋Γ
None
σϑΥϧτͰinlineʹͳΒͳ͍ͷͳͥʜ
ΠϯϥΠϯԽ͢Δ͕ؔେ͖͍ͱ ੜ͞ΕΔίʔυ͕ංେԽ͢ΔՄೳੑ͕͋Δ
ϥϜμࣜͰͷreturn͕ޡղΛট͖͍͢ /* ͜Εओ؍Ͱ͢ */
noinline
ΠϯϥΠϯԽ͠ͳ͍ؔΛࢦఆͰ͖Δ
None
noinline Modifier
͜ͷؔΠϯϥΠϯల։͞Εͳ͍
ͬͪ͜ͷؔΠϯϥΠϯల։͞ΕΔ
crossinline
ҾͷؔΛinlineؔҎ֎ͷจ຺Ͱ ࣮ߦͰ͖ΔΑ͏ʹ͢Δ
None
None
͞ΕͨؔΛ
Invokableܕͷಗ໊Ϋϥεͷ
injectedFunction()ͱ͍͏ϝιουͷ࣮ʹ͍͍ͨ
abstract class Invokable { fun invoke(arg: String): String { val
before = doSomethingBefore(arg) val injected = injectedFunction(before) return doSomethingAfter(injected) } abstract fun injectedFunction(arg: String): String fun doSomethingBefore(arg: String) = "before$arg" fun doSomethingAfter(arg: String) = "${arg}after" }
abstract class Invokable { fun invoke(arg: String): String { val
before = doSomethingBefore(arg) val injected = injectedFunction(before) return doSomethingAfter(injected) } abstract fun injectedFunction(arg: String): String fun doSomethingBefore(arg: String) = "before$arg" fun doSomethingAfter(arg: String) = "${arg}after" } injectedFunction()ͱ͍͏abstractϝιου
abstract class Invokable { fun invoke(arg: String): String { val
before = doSomethingBefore(arg) val injected = injectedFunction(before) return doSomethingAfter(injected) } abstract fun injectedFunction(arg: String): String fun doSomethingBefore(arg: String) = "before$arg" fun doSomethingAfter(arg: String) = "${arg}after" } invoke()ͱ͍͏ϝιουͷதͰ
abstract class Invokable { fun invoke(arg: String): String { val
before = doSomethingBefore(arg) val injected = injectedFunction(before) return doSomethingAfter(injected) } abstract fun injectedFunction(arg: String): String fun doSomethingBefore(arg: String) = "before$arg" fun doSomethingAfter(arg: String) = "${arg}after" } ͏
ίϯύΠϧΤϥʔ
None
None
crossinline Modifier
͑Δ
reified
inlineؔͰ ܕύϥϝʔλʹΞΫηεՄೳʹ͢Δ
ܕύϥϝʔλ
ClassΫϥεΛҾʹऔΔ
ಉ͡ܕͷListΛฦ͢
͞ΕͨํʹΑͬͯॲཧΛ͚Δ
None
None
None
inline Modifier
reified Modifier
Ҿແ͠
ܕύϥϝʔλ͕ར༻Ͱ͖Δ
None
ܕΛએݴ͢Δ
Ҿͳ͠Ͱ࣮ߦ
ܕΛਪ͢Δ
ܕΛࢦఆ࣮ͯ͠ߦ
None
None
ActivityΫϥεͷ֦ுؔ
reifiedΛ͚ͭͯΞΫηεՄೳʹ
Activity.findViewById()ͷΓΛ
ܕύϥϝʔλͰࢦఆ͞ΕΔܕʹΩϟετͯ͠ฦ͢
ܕએݴΛ͢Δ
ຖճΩϟετΛॻ͘ඞཁ͕ͳ͘ͳΔ
None
tailrec
ඌ࠶ؼͳؔͷ࣮ߦΛ࠷దԽ͢Δ
ඌ࠶ؼ
wؔܕݴޠͰΑ͘ݟΔελΠϧ wϧʔϓͷॲཧΛସ͢Δ wؔͷ࠷ޙʹࣗΛݺͼग़͢
None
tailrec Modifier
දࣔ͢Δϝοηʔδ
දࣔ͢Δճ
ճ͕0ҎԼͷ࣌return
ϝοηʔδΛදࣔͯ͠
ճΛݮΒͯࣗ͠Λݺͼग़͢
tailrecແ͠ͰίϯύΠϧͰ͖Δ
ͳʹ͕ҧ͏ͷ͔ʁ
tailrecແ͠ͷ߹
None
ίϯύΠϧ͞Εͯ΄΅ಉ͡
4UBDL0WFS'MPX͕ى͖ΔՄೳੑ͕ߴ͍
None
tailrec͋Γͷ߹
while͕࣮ߦ͞ΕΔ
ࣗΛݺͼग़͞ͳ͍
4UBDL0WFS'MPX͕ى͖ΔՄೳੑ͕͘ͳΔ
None
4UBDL0WFS'MPX͕ى͖ͳ͍Θ͚Ͱͳ͍
Ҏ্
&OKPZ,PUMJO