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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Tomoya Miwa
August 25, 2018
Programming
440
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
740
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
500
できる!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
910
Android for Carsのお話し
tomoya0x00
1
1.1k
Other Decks in Programming
See All in Programming
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
The Rails Doctrine Decade
koic
2
600
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
4k
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
180
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
610
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
240
Workers Cache を知る
syumai
0
370
ChromeでローカルLLM
ryu1013
0
140
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
780
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
Featured
See All Featured
How to build a perfect <img>
jonoalderson
1
6.1k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Ruling the World: When Life Gets Gamed
codingconduct
0
400
The agentic SEO stack - context over prompts
schlessera
0
970
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
940
Into the Great Unknown - MozCon
thekraken
41
2.8k
My Coaching Mixtape
mlcsv
0
360
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
630
Designing for humans not robots
tammielis
254
26k
Visualization
eitanlees
153
17k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
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かわいい︕