What’re the main differences between Kotlin and Sc...
# getting-started
f
What’re the main differences between Kotlin and Scala? I mean, I started using Kotlin this weekend and feel many similarities for an intermediate programmer between both languages.
n
as someone who's learning Scala, on the surface there are a lot of similarities in syntax
but Kotlin aims to be more pragmatic and easier to learn and use. also aims for good Java interop
and there were a lot of...interesting...decisions made in the Scala language, like creating their own collections framework, or implicit type conversions, or IIRC the way generics are implemented
f
What features Kotlin has, and Scala doesn’t?
Well, I will use both hahaha
r
the way generics are implemented
what did Scala do with generics?
e
I'm not sure what Max is referring to there; they use similar declaration-side variance as Kotlin. syntax is oddly `[+T]`/`[-T]`/`[T]` instead of `<out T>`/`<in T>`/`<T>` though
IMO the main difference is that Kotlin avoids many of the more questionable design choices of Scala
what does Scala's
_
mean? long list of rules. what does Kotlin's
it
mean? simple.
and yeah, Kotlin is pragmatic. Scala has some features like non-local returns and structural typing that are simply expensive to implement on the JVM, and Kotlin just doesn't have them.
n
I just remember reading the Scala book and there being a lot of sections about the type system (half the book? more?) and never actually understanding generics
e
well, Scala does have a lot of type-related machinery, with more manipulation being possible at compile-time (such as mixin traits) and runtime (such as reified generics backed by implicit values), but I wouldn't call those part of generics exactly
n
I'm probably misremembering 😅 it was a few years ago. but yeah, relearning Scala and things like ++: and +: for various collection manipulations, plus how you can say
new Instance() with Interface1 with Interface2
is...on that list of interesting choices
e
(to be fair,
object : Instance(), Interface1, Interface2 {}
is legal in Kotlin, but there are certain patterns that can't be expressed. aside from some inherent awkwardness, Scala has a self type and Kotlin doesn't, which makes a difference for some of those uses)
f
I didn’t use Generics yet, but I studied and felt a bit complex. I think it is essential to know to program more deeply. I’m not a developer but a Ph.D. student and a data scientist. I use Python and have been studying Scala and Spark.
So, significant differences are related to advanced things