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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
170
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
240
AIがコードを書いてくれる時代、我々は何を確かめるのか
yosuke_furukawa
PRO
13
5.8k
Performance Optimization With LLMs
xleitix
0
250
オーケストレーション記述言語 Katari
yukikurage
0
240
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
150
まずはコードより業務と向き合う:テーブル解体のためにPdMを呼んだ話
sakawe_ee
0
190
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
330
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
4
1.8k
Railsバージョンを4倍にした話
optim
0
970
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.3k
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
150
Featured
See All Featured
HDC tutorial
michielstock
2
1k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.4k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
470
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
Embracing the Ebb and Flow
colly
88
5.2k
Mind Mapping
helmedeiros
1
430
Exploring anti-patterns in Rails
aemeredith
4
560
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
350
Fireside Chat
paigeccino
43
4.1k
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かわいい︕