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
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
160
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
360
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
fs2-io を試してたらバグを見つけて直した話
chencmd
0
240
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
190
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
Zoneless Testing
rainerhahnekamp
0
120
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
110
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
500
たのしいparse.y
ydah
3
120
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
3
300
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
190
Featured
See All Featured
Scaling GitHub
holman
458
140k
KATA
mclloyd
29
14k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
RailsConf 2023
tenderlove
29
940
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Docker and Python
trallard
42
3.1k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Adopting Sorbet at Scale
ufuk
73
9.1k
A better future with KSS
kneath
238
17k
Six Lessons from altMBA
skipperchong
27
3.5k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
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