1
Sprache als Werkzeug
DSLs mit Kotlin
@toddquackenbush on Unsplash
@maverick_1601
Frank Scheffler
2
DSLs in Kotlin
https://kotlinlang.org/docs/reference/type-safe-builders.html
3
Domain Specific Languages: Definition
“DSLs are small languages, focused on a
particular aspect of a software system.
You can't build a whole program with a DSL,
but you often use multiple DSLs in a
system mainly written in a general purpose
language.”
- Martin Fowler with Rebecca Parsons
https://images-eu.ssl-images-amazon.com/images/I/51qFZ0yIUsL.jpg
4
Domain Specific Languages: Definition
“DSLs come in two main forms: external
and internal. An external DSL is a language
that's parsed independently of the host
general purpose language: good examples
include regular expressions and CSS.”
- Martin Fowler with Rebecca Parsons
https://images-eu.ssl-images-amazon.com/images/I/51qFZ0yIUsL.jpg
5
Domain Specific Languages: Definition
“Internal DSLs are a particular form of API
in a host general purpose language, often
referred to as a fluent interface. The way
mocking libraries, such as JMock, define
expectations for tests are good examples
of this.”
- Martin Fowler with Rebecca Parsons
https://images-eu.ssl-images-amazon.com/images/I/51qFZ0yIUsL.jpg
6
Kotlin Internal DSL Selection
Gradle Kotlin DSL
https://github.com/gradle/kotlin-dsl
Beans/Router/MockMvc DSL
https://github.com/spring-projects/spring-framework
Kotlin Test
https://github.com/kotlintest/kotlintest
Kuery SQL in Kotlin
https://www.kotlinresources.com/library/kuery/
Spring Fu Microframework
https://github.com/spring-projects/spring-fu
GeoJSON Builder DSL
https://github.com/dxfrontiers/kotlin-geojson-dsl
7
1. Predictable
Domain logic is expressed declaratively, while execution is controlled by the DSL.
2. Safer
Restricted dialect and clearer scoping reduces unsafe operations.
3. More expressive
Domain code clearly expresses what should be done. Domain specific errors are easier to understand.
4. Portable
Domain logic execution can be ported to new platforms, if necessary.
5. Easier to understand
Domain experts are able to learn the DSL in less time.
DSL Advantages
8
Building Blocks for DSLs in Kotlin 1/2
Simplified Lambda Syntax
Extension Functions
9
Building Blocks for DSLs in Kotlin 2/2
Lambdas with Receiver
Operator Overloading
10
A Gherkin Test DSL
“Gherkin uses a set of special
keywords to give structure
and meaning to executable
specifications.”
- Cucumber
GIVEN
state before
behavior is
applied
WHEN
specifies the
behavior part
THEN
defines changes
or expected
outcome
11
The Calculator: Classical Verification
12
The Calculator: Gherkin-Style Verification
“given”-Lambda
yields the test
subject
“when”-Lambda receives
test subject and returns
test execution result
“then”-Lambda receives
an assertion object
wrapping the test result
13
Gherkin DSL: Capturing the “test setup”
14
Gherkin DSL: Capturing the “execution result”
15
Gherkin DSL: Triggering test and verification
16
Gherkin DSL: Extensibility
optional assertion
chaining
repeated/parallel
test execution
repeated/clean test
subject creation
17
The infamous Greeter
18
Using Infix Extension Functions
19
Scoping Infix Extension Functions
20
Providing type-safe Asserters
21
Almost unlimited possibilities ...
Some homework
for you!
22
Kotlin DSL Building Blocks
1. Capturing declarations/logic using Lambdas
2. Providing Declarative Context using Lambdas with Receiver
3. Providing scoped (extension) functions
4. Improving Readability using infix notation
5. (Operator overloading)
23
What’s the next DSL you’ll be designing?
Sprache als Werkzeug
DSLs mit Kotlin
https://github.com/dxfrontiers/kotlin-gherkin-dsl/tree/kkon
https://www.heise.de/developer/artikel/Sprache-als-Werkzeug-DSLs-mit-Kotlin-bauen-4599797.html
https://blog.digitalfrontiers.de
@maverick_1601
https://github.com/maverick1601
https://bit.ly/2EDAagi
Frank Scheffler

More Related Content

PPTX
OpenDaylight and YANG
PPTX
Gluecon 2018 JaC
PPTX
Supporting Digital Media Workflows in the Cloud with Perforce Helix
PDF
Yang in OpenDaylight
PDF
Kafka Needs No Keeper
PPTX
What's New in WCF 4.5
PDF
Flink Forward San Francisco 2019: Elastic Data Processing with Apache Flink a...
PDF
Open Network Operating System
OpenDaylight and YANG
Gluecon 2018 JaC
Supporting Digital Media Workflows in the Cloud with Perforce Helix
Yang in OpenDaylight
Kafka Needs No Keeper
What's New in WCF 4.5
Flink Forward San Francisco 2019: Elastic Data Processing with Apache Flink a...
Open Network Operating System

What's hot (20)

PDF
Augmenting Flow Operations and Feedback on the Model Driven MD_SAL Approach i...
PDF
Introduction to YANG data models and their use in OpenDaylight: an overview
PPTX
How to Reduce Database Load with Sparse Branches
PPTX
EF Core (RC2)
PPTX
Enterprise Software Architecture styles
PPTX
DEVNET-1006 Getting Started with OpenDayLight
PDF
Stackato v6
PPTX
Go programming language
PDF
Managing Open Source Software in the GitHub Era
PDF
The Fn Project by Jesse Butler
PDF
Serverless Boston @ Oracle Meetup
PPTX
LAB - Component Based Development
PDF
2.3 (Architecture) Moving to Managed Code
PPTX
Netflix's Transition to High-Availability Storage (QCon SF 2010)
PDF
Lets build-ruby-app-server: Vineet tyagi
PPTX
(ATS3-DEV04) Introduction to Pipeline Pilot Protocol Development for Developers
PDF
Perl-Critic
PDF
nexB Software Audit M&A: What to expect as a Seller
PDF
Code Review with Sonar
PPTX
RSocket — new Reactive cross-network Protocol? Олег Докука и Игорь Лозинский
Augmenting Flow Operations and Feedback on the Model Driven MD_SAL Approach i...
Introduction to YANG data models and their use in OpenDaylight: an overview
How to Reduce Database Load with Sparse Branches
EF Core (RC2)
Enterprise Software Architecture styles
DEVNET-1006 Getting Started with OpenDayLight
Stackato v6
Go programming language
Managing Open Source Software in the GitHub Era
The Fn Project by Jesse Butler
Serverless Boston @ Oracle Meetup
LAB - Component Based Development
2.3 (Architecture) Moving to Managed Code
Netflix's Transition to High-Availability Storage (QCon SF 2010)
Lets build-ruby-app-server: Vineet tyagi
(ATS3-DEV04) Introduction to Pipeline Pilot Protocol Development for Developers
Perl-Critic
nexB Software Audit M&A: What to expect as a Seller
Code Review with Sonar
RSocket — new Reactive cross-network Protocol? Олег Докука и Игорь Лозинский
Ad

Similar to Sprache als Werkzeug: DSLs mit Kotlin (JAX 2020) (20)

PPTX
PDF
Log cat kotlindsl
PPTX
JUG Lausanne - Kotlin DSL
PPTX
Nice to meet Kotlin
PDF
Kotlin DSLs
PDF
Building dsl using groovy
PPTX
Using Kotlin, to Create Kotlin, to Teach Kotlin, in Space
PDF
Devoxx Ukraine 2018 - Kotlin DSL in under an hour
PDF
2017: Kotlin - now more than ever
PDF
GeeCON Prague 2018 - Kotlin DSL in under an hour
PDF
Golang and Domain Specific Languages - Lorenzo Fontana - Codemotion Rome 2017
PPTX
Java One - Designing a DSL in Kotlin
PDF
DSLs: what, why, how
PDF
JavaZone 2022 - Building Kotlin DSL.pdf
PDF
9054799 dzone-refcard267-kotlin
PPTX
Specification Scala DSL for Mobile Application
PPTX
AestasIT - Internal DSLs in Scala
PPTX
ConFoo - Designing a DSL in Kotlin
PDF
Writing a DSL for the Dense with Scala - JVMCon
PDF
Why Kotlin is your next language?
Log cat kotlindsl
JUG Lausanne - Kotlin DSL
Nice to meet Kotlin
Kotlin DSLs
Building dsl using groovy
Using Kotlin, to Create Kotlin, to Teach Kotlin, in Space
Devoxx Ukraine 2018 - Kotlin DSL in under an hour
2017: Kotlin - now more than ever
GeeCON Prague 2018 - Kotlin DSL in under an hour
Golang and Domain Specific Languages - Lorenzo Fontana - Codemotion Rome 2017
Java One - Designing a DSL in Kotlin
DSLs: what, why, how
JavaZone 2022 - Building Kotlin DSL.pdf
9054799 dzone-refcard267-kotlin
Specification Scala DSL for Mobile Application
AestasIT - Internal DSLs in Scala
ConFoo - Designing a DSL in Kotlin
Writing a DSL for the Dense with Scala - JVMCon
Why Kotlin is your next language?
Ad

Recently uploaded (20)

PPTX
1402_iCSC_-_RESTful_Web_APIs_--_Josef_Hammer.pptx
PDF
BIOCHEM CH2 OVERVIEW OF MICROBIOLOGY.pdf
PDF
Computer Networking, Internet, Casting in Network
PDF
KEY COB2 UNIT 1: The Business of businessĐH KInh tế TP.HCM
PPTX
COPD_Management_Exacerbation_Detailed_Placeholders.pptx
PPTX
The-Importance-of-School-Sanitation.pptx
PDF
Session 1 (Week 1)fghjmgfdsfgthyjkhfdsadfghjkhgfdsa
PDF
Understand the Gitlab_presentation_task.pdf
PPTX
IPCNA VIRTUAL CLASSES INTERMEDIATE 6 PROJECT.pptx
PDF
simpleintnettestmetiaerl for the simple testint
PPT
12 Things That Make People Trust a Website Instantly
DOCX
Memecoinist Update: Best Meme Coins 2025, Trump Meme Coin Predictions, and th...
PPTX
KSS ON CYBERSECURITY INCIDENT RESPONSE AND PLANNING MANAGEMENT.pptx
PPTX
Top Website Bugs That Hurt User Experience – And How Expert Web Design Fixes
PDF
Buy Cash App Verified Accounts Instantly – Secure Crypto Deal.pdf
PPTX
MY PRESENTATION66666666666666666666.pptx
PDF
Uptota Investor Deck - Where Africa Meets Blockchain
PDF
The_Decisive_Battle_of_Yarmuk,battle of yarmuk
PPTX
ECO SAFE AI - SUSTAINABLE SAFE AND HOME HUB
PPTX
在线订购名古屋艺术大学毕业证, buy NUA diploma学历认证失败怎么办
1402_iCSC_-_RESTful_Web_APIs_--_Josef_Hammer.pptx
BIOCHEM CH2 OVERVIEW OF MICROBIOLOGY.pdf
Computer Networking, Internet, Casting in Network
KEY COB2 UNIT 1: The Business of businessĐH KInh tế TP.HCM
COPD_Management_Exacerbation_Detailed_Placeholders.pptx
The-Importance-of-School-Sanitation.pptx
Session 1 (Week 1)fghjmgfdsfgthyjkhfdsadfghjkhgfdsa
Understand the Gitlab_presentation_task.pdf
IPCNA VIRTUAL CLASSES INTERMEDIATE 6 PROJECT.pptx
simpleintnettestmetiaerl for the simple testint
12 Things That Make People Trust a Website Instantly
Memecoinist Update: Best Meme Coins 2025, Trump Meme Coin Predictions, and th...
KSS ON CYBERSECURITY INCIDENT RESPONSE AND PLANNING MANAGEMENT.pptx
Top Website Bugs That Hurt User Experience – And How Expert Web Design Fixes
Buy Cash App Verified Accounts Instantly – Secure Crypto Deal.pdf
MY PRESENTATION66666666666666666666.pptx
Uptota Investor Deck - Where Africa Meets Blockchain
The_Decisive_Battle_of_Yarmuk,battle of yarmuk
ECO SAFE AI - SUSTAINABLE SAFE AND HOME HUB
在线订购名古屋艺术大学毕业证, buy NUA diploma学历认证失败怎么办

Sprache als Werkzeug: DSLs mit Kotlin (JAX 2020)

  • 1. 1 Sprache als Werkzeug DSLs mit Kotlin @toddquackenbush on Unsplash @maverick_1601 Frank Scheffler
  • 3. 3 Domain Specific Languages: Definition “DSLs are small languages, focused on a particular aspect of a software system. You can't build a whole program with a DSL, but you often use multiple DSLs in a system mainly written in a general purpose language.” - Martin Fowler with Rebecca Parsons https://images-eu.ssl-images-amazon.com/images/I/51qFZ0yIUsL.jpg
  • 4. 4 Domain Specific Languages: Definition “DSLs come in two main forms: external and internal. An external DSL is a language that's parsed independently of the host general purpose language: good examples include regular expressions and CSS.” - Martin Fowler with Rebecca Parsons https://images-eu.ssl-images-amazon.com/images/I/51qFZ0yIUsL.jpg
  • 5. 5 Domain Specific Languages: Definition “Internal DSLs are a particular form of API in a host general purpose language, often referred to as a fluent interface. The way mocking libraries, such as JMock, define expectations for tests are good examples of this.” - Martin Fowler with Rebecca Parsons https://images-eu.ssl-images-amazon.com/images/I/51qFZ0yIUsL.jpg
  • 6. 6 Kotlin Internal DSL Selection Gradle Kotlin DSL https://github.com/gradle/kotlin-dsl Beans/Router/MockMvc DSL https://github.com/spring-projects/spring-framework Kotlin Test https://github.com/kotlintest/kotlintest Kuery SQL in Kotlin https://www.kotlinresources.com/library/kuery/ Spring Fu Microframework https://github.com/spring-projects/spring-fu GeoJSON Builder DSL https://github.com/dxfrontiers/kotlin-geojson-dsl
  • 7. 7 1. Predictable Domain logic is expressed declaratively, while execution is controlled by the DSL. 2. Safer Restricted dialect and clearer scoping reduces unsafe operations. 3. More expressive Domain code clearly expresses what should be done. Domain specific errors are easier to understand. 4. Portable Domain logic execution can be ported to new platforms, if necessary. 5. Easier to understand Domain experts are able to learn the DSL in less time. DSL Advantages
  • 8. 8 Building Blocks for DSLs in Kotlin 1/2 Simplified Lambda Syntax Extension Functions
  • 9. 9 Building Blocks for DSLs in Kotlin 2/2 Lambdas with Receiver Operator Overloading
  • 10. 10 A Gherkin Test DSL “Gherkin uses a set of special keywords to give structure and meaning to executable specifications.” - Cucumber GIVEN state before behavior is applied WHEN specifies the behavior part THEN defines changes or expected outcome
  • 12. 12 The Calculator: Gherkin-Style Verification “given”-Lambda yields the test subject “when”-Lambda receives test subject and returns test execution result “then”-Lambda receives an assertion object wrapping the test result
  • 13. 13 Gherkin DSL: Capturing the “test setup”
  • 14. 14 Gherkin DSL: Capturing the “execution result”
  • 15. 15 Gherkin DSL: Triggering test and verification
  • 16. 16 Gherkin DSL: Extensibility optional assertion chaining repeated/parallel test execution repeated/clean test subject creation
  • 21. 21 Almost unlimited possibilities ... Some homework for you!
  • 22. 22 Kotlin DSL Building Blocks 1. Capturing declarations/logic using Lambdas 2. Providing Declarative Context using Lambdas with Receiver 3. Providing scoped (extension) functions 4. Improving Readability using infix notation 5. (Operator overloading)
  • 23. 23 What’s the next DSL you’ll be designing? Sprache als Werkzeug DSLs mit Kotlin https://github.com/dxfrontiers/kotlin-gherkin-dsl/tree/kkon https://www.heise.de/developer/artikel/Sprache-als-Werkzeug-DSLs-mit-Kotlin-bauen-4599797.html https://blog.digitalfrontiers.de @maverick_1601 https://github.com/maverick1601 https://bit.ly/2EDAagi Frank Scheffler