I found this comparision: http://confluence.jetbrains.net/display/Kotlin/Comparison+to... so basically Kotlin seems to be a "watered" Scala.
I found this comparision: http://confluence.jetbrains.net/display/Kotlin/Comparison+to... so basically Kotlin seems to be a "watered" Scala.
That being said, the one really cool feature Kotlin has that Scala doesn't is the ability to build strongly-typed builder DSLs:
http://confluence.jetbrains.net/display/Kotlin/Type-safe+Gro...
You simply can't accomplish this in Scala with the same elegance.
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...
For a good example check out the Specs2 unit testing framework.
But doesn't Ruby also have those builders? Wouldn't it be easy enough for Scala to implement them in a library if they haven't already? Wouldn't Python also provide this type of syntax? E.g. a possible translation into Python from the Kotlin code on the linked page...
html:
head:
title {"XML encoding with Python"}
body:
h1 {"XML encoding with Python"}
p {"this format can be used as an alternative markup to XML"}
// an element with attributes and text content
a(href = "http://python.org") {"Python"}
// mixed content
p:
"This is some"
b {"mixed"}
"text. For more see the"
a(href = "http://python.org") {"Python"}
"project"
p{"some text"}
// content generated by
p:
for (arg in args) arg
So what are they called "Groovy-style" builders for?So yea, any language which supports closures should be able to do "Groovy-style" builders.
That could've been very true 6 years ago, when Groovy 1.0 was released, but I'd have to challenge that for 2012 (and 2013).
Most people who use Scala, use it simply as a better Java. Well, Kotlin is that better Java they've actually been looking for all along. And for anyone looking for a truly modern, opinionated language -- there's Clojure.
Most people who end up hating Scala (or at least ruling out its use) seem to be unhappy with the tooling (mainly compile times or out of date IDE modules), rate of language change (either scala or even worse, scalaz), or the inconsistency of interfaces.
Since I only write Java for Android Kotlin is already way ahead of Scala on my list for both reasons.