Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
How useful Kotlin/Native in Kotlin 1.3
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Masaya Yashiro
July 21, 2020
Programming
470
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
How useful Kotlin/Native in Kotlin 1.3
Masaya Yashiro
July 21, 2020
More Decks by Masaya Yashiro
See All by Masaya Yashiro
拡大期を迎えたプロダクトに起きたこと - Android編
yashims
0
630
UX design trend 2019
yashims
5
1.7k
Kotlin/MPP getting started and troubles
yashims
0
4.2k
C# code refactoring with Scope Functions
yashims
0
3k
ココがダメだよWebCamTexture
yashims
0
140
Introduction of MaterialDesign for engineer
yashims
0
120
Other Decks in Programming
See All in Programming
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
160
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
640
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
4
4.7k
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
970
SREの越境 / SRE Collaboration
y0hgi
2
300
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
380
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
330
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2.3k
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
370
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.1k
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
Featured
See All Featured
Ruling the World: When Life Gets Gamed
codingconduct
0
400
YesSQL, Process and Tooling at Scale
rocio
174
15k
Bash Introduction
62gerente
615
220k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
Typedesign – Prime Four
hannesfritz
42
3.2k
Embracing the Ebb and Flow
colly
88
5.2k
Chasing Engaging Ingredients in Design
codingconduct
0
360
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Optimizing for Happiness
mojombo
378
71k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Transcript
Kotlin/Nativeで今どこまで できるか 2020-07-20 吉祥寺.pm #23 @yashims85
誰? 名前: 屋代昌也 会社: 株式会社モバイルファクトリー Twitter: @yashims85 Github: yashims
None
皆さんPerlのどういったところが好 きでしょうか?
Perlで私が好きなところ • コーディングスタイルの自由度が高い • 書き捨てのコードも書きやすい • 資産が豊富 • XSである程度早く実行することもできる •
正規表現が楽 • 言語レベルまでハックできる 触ってて面白い言語だと感じてます。もしあなたがこの辺に好 感を感じるなら、そんなあなたにおすすめしたい言語がありま す。
Kotlin
Kotlinではどの程度カバーできるか コーディングスタイルの自由度が高い 常識の範囲内で高い 書き捨てのコードが書きやすい スクリプトとして実行できる 資産が豊富 Javaの資産を使える(JVMでは) XSである程度早くできる Kotlin/Nativeで機械語出力もできる 正規表現が楽
特段楽ではない 言語レベルまでハックできる できない
今日話したいこと • Kotlin/Nativeで何? • Kotlin/Nativeで今どこまでできるのか
Kotlin/Native • もともとJVM言語として作られたKotlinの拡張 • Kotlin 1.3 からpreview版として使用可能 • KotlinのコードをLLVMでクロスコンパイルして機械語を 吐き出そうという試み
• Kotlin/NativeとともにKotlin/JS拡張も平行で進行中
Kotlin/JVM Kotlin/Native Kotlin/JS
Kotlin/MPP(Multi Platform Project) Kotlin/MPP Kotlin/JVM Kotlin/Native Kotlin/JS Kotlin/Android ServerSide Kotlin
Kotlin/iOS Kotlin/MacOS Kotlin/X86 Kotlin/WinGW Kotlin/Common
Kotlin/MPPによってどんな嬉しい ことがあるのか
設計をコードレベルで共有できるよ うになる
Android/iOSビジネスロジック共通化 アプリインターフェースパッケー ジ(Kotlin/Android) アプリインターフェースパッケー ジ(Swift) バックエンドライブラリ(Kotlin/MPP) ビジネスロジック リソースロジック Appサーバ OS
Firebase Activity, Fragment View ViewControll er View
更にサーバもKotlinにしてしまえば APIの型中間表現とか不要になっ て。。 とか考えると夢が膨らみますね。
で、実際のところその設計はどの程 度まで実現できるの?
A: Androidは問題なく動く
A: iOSは不可侵領域に踏み込まな ければ動く 以降のiOSの場合の話はKotlin/Native(以降K/N)の 厄介さの話です。 Kotlin/JVMを触ってる限りは考慮に入れるひつようは ありません。
不可侵 領域
バックグラウンドスレッド
不可侵領域: バックグラウンドスレッド Kotlin 1.3 ではバックグラウンドスレッドはサポートされていな い。 KotlinにはMPPをサポートする非同期処理として Coroutine がある。これを使用してスレッドを切り替えることはもちろん、 バックグラウンドスレッドで実行されている
Swiftコードから呼 び出すのもダメ。 これは、後述するfreezeルールと関連する。
freezeルール
不可侵領域: freezeルール class Sample { var value: Int = 0
fun increment(): Int { value++ Log.d("incremented: $value") return value } } 問題: increment() メソッドは必ず元の値から +1された値を返 すでしょうか?
答え: NO
不可侵領域: freezeルール class Sample { var value: Int = 0
fun increment(): Int { value++ Log.d("incremented: $value") return value } } メンバ変数はスレッド間で共通のため、トランザクション分離レ ベルを意識する必要がある。 この間に別Threadで increment()が走るかもし れない
不可侵領域: freezeルール K/Nではこのメンバ変数のトランザクション分離レベルの問題 を回避するためにfreezeの制約が存在する。 メンバ変数に実体を置く時は、freezed内部フラグを立てて、 変数をimmutableにしないと、他のスレッドで触ることが出来 ない。
不可侵領域: FAQ • シングルトンの場合freezeルールどうなるの? ◦ そこが、Mainスレッド以外で動作が保証されない理由 ◦ 副作用の無い処理なら問題ないが、副作用がある処理の 場合、適切に処理されていないと、シングルトンを instantiateしたスレッドでしか触れなくなる
• どのK/Nライブラリでシングルトンを使っているかわからない ◦ Kotlin 1.3では、K/NはMainスレッド以外は動作対象外な ので全部諦めよう。 • 非同期処理(Coroutine等)は使えないの? ◦ Mainスレッドで遅延実行すればできるよ
不可侵領域要約: Kotlin 1.3 の現状では、Mainス レッド以外が厳しみ
さて皆さんこの状況お気づきでしょう か。
Android/iOSビジネスロジック共通化 アプリインターフェースパッケー ジ(Kotlin/Android) アプリインターフェースパッケー ジ(Swift) バックエンドライブラリ(Kotlin/MPP) ビジネスロジック リソースロジック Appサーバ OS
Firebase Activity, Fragment View ViewControll er View バックエンドを共通化し たいのにバックグラウ ンドスレッドでうまく動か ないとはこれ如何に
まとめ • 普通にJVMで使う分には何も問題無い • Kotlin/Nativeに手を出すとKotlin 1.3現在ではまだ早 い • KotlinいいよKotlin
詠みます
“ 僕らは何度も共通化の夢をみる 徒花と知りつつも
ありがとうございました