The next major release for the promising JVM language Kotlin by JetBrains has now been published (read the release notes here). The most prominent features of this version are the finalization of coroutines and a beta release for Kotlin/Native. Version 1.3 is an important step forward for Kotlin. With coroutines, the release brings a stable mechanism to the language for writing concurrent applications in a concise and easy to maintain way. Kotlin/Native allows the compilation of Kotlin code into native code for a decent number of target platform. You can, for instance, compile Kotlin code into native executables or libraries for iOS, Windows, MacOS, the web (WebAssembly), and more. Together with Kotlin’s aim to facilitate multiplatform projects, it will be possible to share code between these platforms so that only a single Kotlin code base needs to be maintained.
According to Wikipedia,
Coroutines are computer-program components that generalize subroutines for non-preemptive multitasking, by allowing multiple entry points for suspending and resuming execution at certain locations. Coroutines are well-suited for implementing familiar program components such as cooperative tasks, exceptions, event loops, iterators, infinite lists and pipes.
Using this principle, Kotlin allows you to add concurrency to your programs whithout having to explicitly manage and synchronize threads. While conceptually not the same, a concept very much akin to coroutines are reactive streams. Kotlin coroutines allow to interoperate with reactive streams and can be used together with these. This opens a wide range of possibilities for implementing asynchronous and non-blocking applications.
The differences between coroutines and reactive streams are described in this guide.
This cross-compiling option is taken one step further with Kotlin/Native and multiplatform projects. Kotlin uses LLVM for compiling to native binaries. By that, Kotlin code can run in environments where a virtual machine is not available or not desirable, such as embedded systems or on iOS. Furthermore, it is possible to use existing native libraries, written in C, C++, Swift, Objective-C, and others, and to reuse Kotlin libraries in applications written in these languages.
Besides these two important steps forward, Kotlin 1.3 brings some more smaller changes:
- A beta release for the connected applications framework Ktor which makes use of coroutines. This framework aims at helping to build asynchronous servers and clients in connected systems, e. g. microservices.
- Experimental support for inline classes which allow to define a kind of a typesafe alias for primitive data types.
- Contracts to improve static analysis for library calls.
- … and more.
Full support for the new features will be bundled in IntelliJ IDEA 2018.3 and can be installed into earlier versions by updating the Kotlin plugin.