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
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.5k
Re:VIEWで書いた「Compose で Android の edge-to-edge に対応する」をRoo Codeで発表資料にしてもらった
tomoya0x00
0
730
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
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.4k
setup-vp GitLab対応の裏側
naokihaba
0
150
iOSDCのペンライトを自動制御したい!
akkeylab
0
340
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
290
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
120
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.3k
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
570
FreeBSDでZabbixを動かす
kenkino
0
350
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
270
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
170
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
160
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
Building Adaptive Systems
keathley
44
3.2k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
710
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
350
For a Future-Friendly Web
brad_frost
183
10k
Optimising Largest Contentful Paint
csswizardry
37
4k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
450
Six Lessons from altMBA
skipperchong
29
4.5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
590
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かわいい︕