What’s the diff: Trailing commas, unified backends, better performance, oh my – Kotlin language hits 1.4

Kotlin programming language

IDE provider JetBrains has released version 1.4 of its JVM and Android-targeting programming language Kotlin into the wild. A good 4.5 years after presenting the first major version, the team focused on the overall developer experience for v1.4, while new language features and unified compiler backends are meant to push performance and consistency.

The new iteration for example finally brings the long awaited single abstract method conversion for Kotlin interfaces, something that was previously only available when working with Java methods and interfaces, meant to help make code more concise and readable

It ends the strict order of positional before named arguments when calling a function, and lets the project join the ranks of programming languages allowing trailing commas, so that developers can reorder or add items to enumerations easier. Other than that Kotlin 1.4 includes an explicit API mode for library authors with extra checks to make a library’s programming interface clearer and more consistent, and a couple of improvements to callable references. 

To improve the language’s performance, the Kotlin team has also been busy moving its compiler refresh forward. Besides a new algorithm for type inference, one major work item was the unification of the three backends for executable generation included in the project. The aim of this release was to get Kotlin/JVM and Jotlin/JS to use the same internal representation Kotlin/Native uses for Kotlin code. To make that happen, they now use a lot of the same logic and an harmonised pipeline, which will make it easier to get fixes and new features into all backends in the future. 

Advertisement

Both new backends are currently in alpha state but are said to become the default in one of the next updates. Users interested in enabling the new JVM backend need to add the compiler option kotlinOptions.useIR = true to their Gradle script. They are also advised to take a look at the kotlin.js documentation, since the Gradle plugin’s domain-specific language has seen the addition of some more configuration options and adjustments to make it a bit more coherent with kotlin-multiplatform’s DSL.

Meanwhile Kotlin/JS users can get the new backend version working by setting “the key kotlin.js.compiler=ir in your gradle.properties, or pass the IR compiler type to the js function of your Gradle build script”. Since it also comes with a new @JsExport annotation, and an option to generate TypeScript definitions from Kotlin code, this might prove especially interesting for developers working with combinations of the two.

Of course Kotlin/Native received some attention as well, sporting – performance improvements aside – basic support for suspending functions in Swift and Objective-C amongst other things. Suspending functions in Kotlin denote functions that can pause and resume coroutines so that resources can be used for other, more pressing tasks. Those are now available as functions with callbacks when a Kotlin module is compiled into Apple frameworks. Other enhancements in the Kotlin/Native backend include default Objective-C generics support, improved exception handling, and the production of debug symbol files for releases on Darwin platforms.

Since JetBrains is mainly a tooling company, it isn’t a huge surprise that IDE improvements, or improvements to the Kotlin IDE plugin, to be more precise, are also part of the 1.4 release. Highlighted enhancements range from quicker autocomplete suggestions to more quick fixes and a flexible Kotlin Project Wizard. 

However, those really deep down the Kotlin-hole will most appreciate the new Coroutine Debugger. It now allows developers to check the state of each coroutine, complete with values of local and captured variables, and presents them with a coroutine creation stack. Additional features are planned to land soon, though JetBrains hopes for feedback to drive further development into the most useful direction.

Kotlin is a programming language targeting the JVM, JavaScript, and LLVM. It made its debut in 2011 as a new JVM language looking to become a better language than Java while being fully interoperable. Kotlin was open-sourced the following year and has since become one of the languages supported in the Android Studio IDE.

Google last year went so far as stating that “Android development will become increasingly Kotlin-first” nudging people to use the language when starting new projects since “code written in Kotlin often means much less code for you–less code to type, test, and maintain”.

- Advertisement -