Upload
nicolas-frankel
View
1.035
Download
0
Embed Size (px)
Citation preview
ME, MYSELF AND I
2
Consultant
• Whatever the customer asks of me
Я изучаю русский язык
• Но мне очень трудно
@nicolas_frankel #kotlin #dsl #kaadin
A DSL?
4
“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
GPL/DSL EXAMPLES
GPL DSL
XML • HTML• MathML
Java • Hamcrest• AssertJ• Fest Assert
Kotlin • Anko• Kaadin
5@nicolas_frankel #kotlin #dsl #kaadin
DESIGNING A DSL IN JAVA
6
Method Sequencing
Method Chaining
Nested Method Calls
Lambdas
https://dzone.com/articles/building-a-dsl-in-java
@nicolas_frankel #kotlin #dsl #kaadin
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");
7@nicolas_frankel #kotlin #dsl #kaadin
KOTLIN
8
“Statically typed programming languagefor the JVM, Android and the browser”
-- http://kotlinlang.org/
@nicolas_frankel #kotlin #dsl #kaadin
A FEW FACTS
9
Developed by JetBrains
• Soon co-managed by Google
Open Source
Compiles to
• JVM bytecode
• JavaScript
• (Native)
A "simpler Scala"
@nicolas_frankel #kotlin #dsl #kaadin
KOTLIN FEATURES
10
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
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);
}
}
11
@nicolas_frankel #kotlin #dsl #kaadin
DECLARATIVE VAADIN UI
class KaadinSampler : UI() {
override fun init(req: VaadinRequest) {
theme = "valo"
verticalLayout(margin = true) {
html("<strong>Hello</strong>")
textField("world!")
}
}
}
13
@nicolas_frankel #kotlin #dsl #kaadin
WHY NOT GROOVY?
email {
from '[email protected]’
to '[email protected]’
subject 'The pope has resigned!’
body {
p 'Really, the pope has resigned!’
}
}
15
@nicolas_frankel #kotlin #dsl #kaadin
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
}
}
16
@nicolas_frankel #kotlin #dsl #kaadin
TAKEAWAYS
1. 100% Java interoperability
2. Properties
3. Extension Functions
4. Named parameters
5. Default values
6. Lambdas with receiver
7. (Operator overloading)
8. (Infix)
17
@nicolas_frankel #kotlin #dsl #kaadin