by ajselvig · 13y ago · 0 comments
In the end, we end up with a builder DSL like this:
div() {
h1("header")
p("paragraph")
div() {
p("another paragraph")
}
h2("another header")
}
In Kotlin, each function call is properly scoped inside (unseen) classes for each level, allowing the code to generate the appropriate object tree.In Scala, all functions would have to be visible in the local scope of the top-level function and we'd end up with a flat object tree instead.
To get the proper object tree in Scala, you'd need to pass explicit references to each containing object into the appropriate function literals, which makes it much more verbose and extremely error prone.
EDIT: not nearly as convincing without proper formatting...
No comments yet.