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
Kotlin で DSL を作り始めるまで
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Tomoya Miwa
August 25, 2018
Programming
450
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kotlin で DSL を作り始めるまで
Kotlin Fest 2018 での 3分 LT です。
Tomoya Miwa
August 25, 2018
More Decks by Tomoya Miwa
See All by Tomoya Miwa
基礎から学ぶ大画面対応(Learning Large-Screen Support from the Ground Up)
tomoya0x00
0
8.6k
Re:VIEWで書いた「Compose で Android の edge-to-edge に対応する」をRoo Codeで発表資料にしてもらった
tomoya0x00
0
750
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
510
できる!ComposeでCollapsingToolbar
tomoya0x00
0
1.1k
Compose の LazyColumn パフォーマンス改善で取り組んだこと
tomoya0x00
0
2.5k
ComposeのMutableStateってどうやってLocal Unit Testすれば良いの??
tomoya0x00
0
1.3k
意外と簡単?Navigation rail導入のお話
tomoya0x00
0
1.7k
Kotlin Coroutines Flow を触ってみた話し
tomoya0x00
2
920
Android for Carsのお話し
tomoya0x00
1
1.1k
Other Decks in Programming
See All in Programming
AIが生成したコードは読むべきか?抽象化設計とコードの品質保証 / abstraction-design-and-quality
minodriven
15
8.4k
AI-Powered Domain-Driven Design
ziobrando
0
380
Crash Auto Pipelines
veronikapj
1
340
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
170
LLM 101
dalinaum
0
460
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
1
180
sbt 2.0: takeoff
eed3si9n
0
190
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
130
Vue.jsで作る空間解析アプリとCapacitorプラグインのData Bridge
hal_spidernight
1
160
Web Framework Benchmark Battle 2026, Any%
a_matsuda
3
3.1k
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
320
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
320
Featured
See All Featured
Building Adaptive Systems
keathley
44
3.3k
Code Reviewing Like a Champion
maltzj
529
40k
Abbi's Birthday
coloredviolet
4
11k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.7k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
350
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
560
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Speed Design
sergeychernyshev
33
2.2k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
610
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
520
Transcript
Kotlin で DSL を作り始めるまで tomoya0x00 Kotlin Fest 2018
⾃⼰紹介 tomoya0x00 Twitter, GitHub, Qiita Android, Embedded system, BLE/BT, iOS
DeNAでタクベルつくってます
DSLとは︖
DSLとは︖ Domain Speci c Language の略で特定ドメインに特化した⾔語 HTMLとか、SQLとかもある意味DSL KotlinやJavaなどのプログラミング⾔語に⽐べて汎⽤性は低い 汎⽤性を下げることで、特定分野で使いやすくしている
DSLの何が嬉しいのか 特定ドメインに特化しているので、読みやすい&書きやすい ボイラープレートのような冗⻑な記述を減らせるかも IDEなどでコード補完できる
FSM DSL in Kotlin https://speakerdeck.com/tomoya0x00/fsm-dsl-in-kotlin 以前、 Kotlin Developers Meetup で
LT させて頂いた
例︓FSM DSL
例︓FSM DSL val sm = stateMachine(initial = MyState.NotLoaned) { state(MyState.NotLoaned)
{ edge(MyEvent.PressRental, next = MyState.Lock) } state(MyState.OnLoan, entry = { println("turnOnRentalLed") }, exit = { println("turnOffRentalLed") }) { state(MyState.Lock) { edge(MyEvent.PressReturn, next = MyState.NotLoaned) edge(MyEvent.PressUnLock, next = MyState.UnLock) } state(MyState.UnLock) { edge(MyEvent.PressLock, next = MyState.Lock) } } }
DSL、作ってみたくなりましたか︖
作り始めるまでの流れをご紹介 ⾃分の実体験+α
Step1 DSLを具体的にどのようにして実現するのか 基本を学んでイメージを掴む
Kotlin Koans
Kotlin Koans This tutorial walks you through a series of
exercises to get familiar with Kotlin. https://kotlinlang.org/docs/tutorials/koans.html
Koans の Builders HTMLを⽣成するDSLをつくるお題
DSLの抜粋 html { table { tr (color = getTitleColor()) {
td { text("Product") } td { text("Price") } td { text("Popularity") } } } }
ほとんどHTML
どうやって実現しているのか︖
説明は省略(時間が⾜りない) Koansやってみてください︕︕
次
Creating DSLs in Kotlin JetBrains 社の Hadi Hariri ⽒による講演 https://www.youtube.com/watch?v=TGdAvY5i-sU
もちろん全部英語ですが、 実際にコードを書きながら説明して下さっている ⼀度 Koans の Builders をやっておけば、より理解しやすい ので、英語苦⼿でもなんとかなると思います︕ (YouTubeの⾃動⽣成英語字幕とっても便利)
⾃分が参考になった点 Builder @DslMarker
説明は省略(時間が⾜りない) 講演動画みてください︕︕
Step2 DSLの⽂法を考える
DSLの⽂法を考える 1. DSL⾃体のmustとwantをまとめる 2. 既存のDSLをググって⾒てみる 3. DSLの⽂法案をまとめる
例︓FSM DSLの場合
1. DSL⾃体のmustとwantをまとめる must ⼊れ⼦の状態遷移に対応(最低でも1階層の⼦を持てる) Composite state onEntry/onExit対応
1. DSL⾃体のmustとwantをまとめる want 状態遷移図が吐ける PlantUML記法で出⼒ 宣⾔的に書ける Testable Android Thingsなどでも使える軽量なもの Rxやcoroutine拡張
2. 既存のDSLをググって⾒てみる "fsm dsl kotlin" でググる︕ 取り⼊れたいところ、逆に改善したいところを⾒つける ⼊れ⼦の状態遷移に対応しているのは⾒当たらない 状態名を⽂字列で渡すのはやめておきたい
3. DSLの⽂法案をまとめる // StateとEventはsealed classとして宣⾔ stateMachine { state(StateA, onEntry =
{}, onExit = {}) { edge(EventA, StateC) {/* action */} state(StateB, onEntry = {}, onExit = {}) } }
この後は︖
この後は︖ 1. まずはDSLのコンパイルだけを通す 2. DSLを実際に動かすために必要なデータ構造を考える(FSMでは重要 だった) 3. DSLから 2. で考えたデータ構造への変換処理を書く
4. データ構造を使⽤して実際に動くコードを書く
Thank you!
Kotlinかわいい︕