Kotlin vs Scala

Comparing of Java Virtual Machine - compatible programming languages
28 August 2017   4161

Java is one of the most popular languages ​​for business applications development. However, because of its enterprise-oriented approach, it is evolving extremely slow, which is not satisfied by all programmers. Therefore, periodically there are new JVM-compatible languages ​​that are designed to solve Java problems.

Two of them are Kotlin and Scala. The first is a relatively new development from JetBrains, fully compatible with the standard Java code and significantly expanding its functionality. Scala represents the symbiosis of Java and C #, combining object-oriented programming with functional.

Let's have a good look at these languages ​​in more detail and understand what their key differences are and how they affect the scope of these development tools.

Complexity of studying

Due to the fact that both languages ​​are based on the Java-based business development framework, the basic threshold for entry into them is quite large. Therefore, it is more logical to compare them in the perspective of a developer already familiar with Java.

Kotlin is extremely similar to his "parent". A Java programmer will easily understand most of the Kotlin code without any specific knowledges. The mastering and learning of additional possibilities like lambda functions also does not take much time.

val numbers = 1..10
val doubles = numbers.map { it * 2 }
val sumOfSquares = doubles.fold(0) {x,y -> x+y }

Scala is a more complex language. It introduces quite a lot of innovations in comparison with Java and serves rather than its "expansion" as Kotlin, but a powerful tool for developers who feel that Java limits them. Accordingly, a comprehensive study of Scala will take a long time.

val numbers = 1 to 10
val doubles = numbers.map { _ * 2 }
val sumOfSquares = doubles.fold(0) { _ + _ }

Programming approach

Kotlin, although it has some signs of a functional language, still gravitates toward object-oriented paradigms. This is a definite plus for programmers, who previously worked only with OOP, but developers who are accustomed to functional programming may not have enough capabilities.

Scala offers great flexibility. When writing code in this language, you can take full advantage of both the object-oriented and functional approach.

Features

  • Type declaration. Both languages ​​are statically typed. Variable type declaration is optional.
  • Null Safely. Scala uses an option monad for this purpose, which can exist in one of two states: Some (x) or None. In Kotlin for error protection, new types of nullable and non-null variables have been added, to which null can not be written. In general, the Kotlin approach makes the code more readable and concise.
  • Classes of data. Scala uses case classes that support methods for creating new instances and declaring properties. Kotlin offers a similar set of features in general, but its classes are more suitable for working with Java-frameworks, because it looks like JavaBean.
  • Scala has problems with the syntax of the infix and postfix operators. Kotlin is a slightly more formalized language, which improves the readability of the code and removes the excessive ambiguity of the syntax.
  • Implicit conversions in Scala can significantly change the behavior of the code after importing - it is difficult to determine exactly which variable will be passed to the function. However, the problem is solved when working in the IDE.
  • Compiling Scala takes longer than Kotlin.

Community and the future of the language

Scala exists since 2003, so it's no wonder that for such a time the language managed to gather around itself a large community of developers. Kotlin is younger, but JetBrains actively support their creation and contribute to its promotion. So, full support for Kotlin will be added to the new version of Android Studio, for example.

In terms of further development on Scala, its JVM compatibility is giving more and more influence: the speed of new functions is slowing down, unresolved problems can be inherited from the version to the version. Kotlin, having set himself the task of not stagnating as Java, has so far coped with it, significantly expanding the arsenal of software.

Conclusion

Kotlin  Scala
Mainly uses object-oriented paradigms with a little support of functional ones Symbiosis of OOP and FP
Simple language studying for Java developers. Scala, is an independent language, with all the resulting difficulties of study.
Convenient functionality for Null Safely. Not convenient functionality for Null Safely.
Faster compilation Slower compilation
Community is in the process of formation. Formed community.
The language is perfect for introducing into existing Java projects and rewriting them to a more convenient and flexible Kotlin. A multifunctional language that can be used both in Java-applications and other projects that are difficult to implement in pure Java.

 

What technology do you choose, Kotlin or Scala?

What programming language do you prefer? Kotlin or Scala? Or maybe you are already using some of them? Please, share your thoughts with the community. Also, after the voting, you will be able to see what people like the most. Your opinion is very valuable for the Hype.Codes team.

Scala
82% (241 votes)
Kotlin
18% (52 votes)
Total votes: 293

JetBrains to Roll Out Ktor Framework

Framework is suitable for writing back-end projects and microservices in the Kotlin language
20 November 2018   184

JetBrains developers told about the release of the stable version of the Ktor 1.0 framework. It helps to create asynchronous servers and clients in related systems. According to the creators, the framework is suitable for writing back-end projects and microservices in the Kotlin language. Documentation and project generator are published on the official website.

First of all, it is worth noting that this is an open source project that is distributed under the Apache 2 license. The main components are:

  • HTTP server running on a virtual machine. It works on Netty, Jetty, and server-side Java programs. It can be placed in a container, embedded in desktop or Android applications, as well as run on Tomcat. Moreover, it corresponds to the paradigm of the application of twelve factors.
  • Multiplatform HTTP client. Although asynchronous, it uses the same coroutines and I / O elements that control the server.

Tools will help the developer to customize the main components of the application.

The Kotlin / Native project supports Ktor, starting with version 0.8. In this case, the working version of Kotlin / Native 0.9 was released in early September 2018. In it, developers added support for unsigned types and interoperability with C, Objective-C / Swift.