What are the main differences between Kotlin and Scala?

14

The differences between Kotlin and Java are very clear, 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 the JVM.

So what are the main differences between Kotlin and Scala? What are the shortcomings in Scala that motivated Kotlin?

    
asked by anonymous 07.08.2017 / 21:00

1 answer

8

I imagine you are wondering why you created Kotlin if Scala already solves these problems, or because they have created a Java better than Java if Scala already does that. If it is not that, I imagine the question is a duplicate.

Perhaps the biggest reason is because Scala is interesting, but it's not exactly Java better than Java. It has moved too much to 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 solved more appropriately in Kotlin.

Truth be told that Kotlin began to be developed when Scala was in 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 could not 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 speak the truth I find the compiler of Kotlin very slow.

There he also says that the set of features does not please. And this is usually the reason for creating a new language. Rarely is there anything new created in market languages, only the existing one is done in a different way with a set and specific intersections different from what already exists, and this makes a difference.

Specifically Kotlin:

  • is a bit more explicit than Scala. Functional languages tend to be very concise sacrificing a little readability. Kotlin opted to be more verbose where he could add something important to the code.
  • is somewhat more geared towards OOP than Scala.
  • Interoperates with better Java.
  • compiles to and interoperates with JavaScript.
  • has Extensions .
  • is safe for use of null values in the language itself.
  • smart casts .
  • uses inline functions for efficiency where possible .
  • treat delegation as First Class .
  • You can call a function by its name as a reference .

On the other hand it does not have:

Certainly there are other things that I do not remember or have not found. You obviously have small syntax differences . There are small differences in each mechanism, for example What is the difference between Kotlin data class and Scala case class? . / p>     

15.08.2017 / 15:11