What are the main differences between Kotlin and Scala?

Asked

Viewed 632 times

17

It is already clear differences between Kotlin and Java, such as:

  • More concise (up to 40% code reduction)
  • Null Safety
  • Type inference
  • Data class
  • Interoperable with Java

However, all these features already exist in Scala, a language that also runs on JVM.

So, what are the main differences between Kotlin and Scala? What are the existing gaps in Scala that motivated Kotlin?

  • 1

    Briefly, the main differences between Kotlin and Scala is that Kotlin is faster and easier to read.

  • 1

    One of them: https://answall.com/q/139839/101

  • @acklay because?

  • 2

    Porém, todas estas características já existem no Scala, uma linguagem que também roda na JVM (...) Quais são as lacunas existentes no Scala que motivaram o Kotlin? No, it is not because there are gaps that things are created. The language ecosystem works most of the time like this: https://xkcd.com/927/

  • @bigown I read some comparisons and that was a conclusion I drew regarding the functioning of the two. That project on Github has a comparison using 4 different shapes. Java, Groovy, Scala and Kotlin. I don’t believe there was any bias in this analysis.

1 answer

12


I imagine you’re wondering why they created Kotlin if Scala already solves these problems, that is, why they created a better Java than Java if Scala already does this? Otherwise I imagine the question is duplicate.

Maybe the biggest reason is because Scala is interesting, but it’s not exactly a better Java than Java. It leaned heavily on the functional side and creates difficulties for the average programmer accustomed to an essentially imperative language. Kotlin keeps the imperative spirit of Java much more than Scala did. The most typical problems that Java solves are best solved in Kotlin.

It is true that Kotlin began to be developed when Scala was at a less advanced stage and had more problems than it has today for the average programmer. Scala is more palatable.

To meet the language requirements a Scala compiler failed to be as efficient. Already Kotlin was thought to have a syntax that favored the compilation. We can say that this is a official reason. Although to tell the truth I find the compiler of Kotlin very slow (maybe Scala is tragic, happens a lot in languages that offer too many facilities).

Ali also says that the set of characteristics did not please. And this is usually the reason to create a new language. You rarely create something new in, market languages, you just do what already exists in a different way with a set and specific intersections different from what already exists, and that makes a difference.

Specifically Kotlin:

  • is a little more explicit than Scala. Functional languages tend to be very concise sacrificing a little readability. Kotlin chose to be more verbose where he can add something important to the code, not as much as Java.
  • is a little more OOP-oriented than Scala.
  • interopera with better Java.
  • compiles for and interoperates with Javascript.
  • possesses Extensions.
  • is safe to use null values in the language itself.
  • has smart Casts.
  • uses inline functions for efficiency where possible.
  • treats the delegation as first class.
  • can call a function by its name as a reference.

On the other hand she doesn’t have:

Surely there are other things I don’t remember or find. Obviously there are small differences in syntax. There are small differences in each mechanism, for example What is the difference between Kotlin data class and Scala case class?. And that may have been out of date over time, there are things that language doesn’t have now, but it’s only a matter of time.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.