Download presentation
Presentation is loading. Please wait.
1
Designing a DSL in KOTLIN
@nicolas_frankel
2
Me, Myself and I By day By night Consultant Developer Blogger
Book author Teacher/trainer @nicolas_frankel #kotlin #dsl #kaadin
3
hybris, an SAP company @nicolas_frankel #kotlin #dsl #kaadin
4
A DSL? “A Domain-Specific Language is a computer language specialized to a particular application domain. This is in contrast to a General-Purpose Language, which is broadly applicable across domains.” -- Wikipedia @nicolas_frankel #kotlin #dsl #kaadin
5
GPL/DSL examples GPL DSL XML HTML MathML Java Hamcrest AssertJ
Fest Assert Kotlin Anko Kaadin Bean DSL @nicolas_frankel #kotlin #dsl #kaadin
6
Designing a DSL in Java Method Sequencing Method Chaining
Nested Method Calls Lambdas @nicolas_frankel #kotlin #dsl #kaadin
7
AssertJ Sample assertThat(frodo.getName()) .startsWith("Fro") .endsWith("do") .isEqualToIgnoringCase("frodo"); assertThat(fellowshipOfTheRing) .filteredOn(c -> c.getName().contains("o")) .containsOnly(aragorn, frodo, legolas) .extracting(c -> c.getRace().getName()) .contains("Hobbit", "Elf", "Man"); @nicolas_frankel #kotlin #dsl #kaadin
8
Kotlin “Statically typed programming language for the JVM, Android and the browser” -- @nicolas_frankel #kotlin #dsl #kaadin
9
A few facts Developed by JetBrains Open Source Compiles to
Soon co-managed by Google Open Source Compiles to JVM bytecode JavaScript (Native) A "simpler Scala" @nicolas_frankel #kotlin #dsl #kaadin
10
Kotlin features Functional and object-oriented Statically-typed
Null safe No checked exceptions Named & optional arguments Lambdas Extension functions Java compatibility (And more...) @nicolas_frankel #kotlin #dsl #kaadin
11
Sample: Vaadin UI public class SampleUI extends UI { @Override protected void init(VaadinRequest req) { setTheme("valo"); VerticalLayout layout = new VerticalLayout(); Label label = new Label("<strong>Hello</strong>", HTML); TextField field = new TextField("world!"); layout.addComponents(label, field); layout.setMargin(true); setContent(layout); } } @nicolas_frankel #kotlin #dsl #kaadin
12
Our goal for DSL “Looks” declarative... But is code
@nicolas_frankel #kotlin #dsl #kaadin
13
Declarative Vaadin UI class KaadinSampler : UI() { override fun init(req: VaadinRequest) { theme = "valo" verticalLayout(margin = true) { html("<strong>Hello</strong>") textField("world!") } } } @nicolas_frankel #kotlin #dsl #kaadin
14
Demo! @nicolas_frankel #kotlin #dsl #kaadin
15
Why not Groovy? { from to subject 'The pope has resigned!’ body { p 'Really, the pope has resigned!’ } @nicolas_frankel #kotlin #dsl #kaadin
16
Why not Scala? object SquareRoot extends Baysick { def main(args:Array[String]) = { 10 PRINT "Enter a number" 20 INPUT 'n 30 PRINT "Square root of " % "'n is " % SQRT('n) 40 END RUN } @nicolas_frankel #kotlin #dsl #kaadin
17
Takeaways 100% Java interoperability Properties Extension Functions
Named parameters Default values Lambdas with receiver (Operator overloading) (Infix) @nicolas_frankel #kotlin #dsl #kaadin
18
Q&A @nicolas_frankel #kotlin #dsl #kaadin
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.