Kotlin – The new swiss army knife among programming languages?

 Impression from the Kotlin Conference 2018
Impression from the Kotlin Conference 2018
 Lots of developers at Kotlin Conference 2018
Lots of developers at Kotlin Conference 2018

How should your perfect programming language should look like? I didn’t had any Idea how to answer that question because for me a programming language was just a tool to solve a specific problem. Until I met Kotlin – and went to this years Kotlin Conference in Amsterdam in early October.

What is Kotlin?

Kotlin is an open source programming language developed by Jetbrains and was released in 2016. It includes OOP and functional Programming as its main paradigms and got picked up very fast by the Android and Java Community. Today Kotlin is used by about 1.5 million developers, got picked up by even more developer communities and has way more use cases than you might think.

What makes Kotlin special? At first glance: nothing. But if you start digging deeper: everything. Starting with the purpose of the language. Kotlin is not another language to solve a problem or having a specific use case. It aims to be a multi-purpose language for all platforms with which you can express your thoughts as code. Kotlin doesn’t care about features never seen. It uses well known features and improve those while maintaining an overall consistency. Kotlin doesn’t want to be separated from other programming languages. It works hard to achieve interoperability and generating synergies with other programming languages. And finally Kotlin is not only a programming language. It also cares about the tooling, the community, the Kotlin ecosystem and that you enjoy working with Kotlin.

Taking the best from others – the ease of converting

That may sound very abstract but it results in many real benefits. It doesn’t matter if you are a Java, Swift or JS developer. You will find Kotlin easy to write, easy to read and very expressive. That is because it is inspired by all of those and offers you different approaches to write your code. Kotlin is offering null-safety, a statically typed system with automatic type inference, data classes and many more modern language features. Projects which converted their code from Java to Kotlin have about 25% less LOC while maintaining the same logic and achieving a better readability. Due to Kotlins interoperability it is possible to call Java, JavaScript, C, Swift and OS functions from your code and vice versa. I want to point out one benefit which was also very prominent at the KontlinConf 2018 in Amsterdam.

Kotlin is built for multiple platforms

Kotlin targets multiple platforms. Kotlin started in 2016 by targeting only the JVM. 2017 Kotlin/JS was introduced which is compiling to JavaScript and can therefore be used for Web-Applications. And in 2018 they introduced Kotlin/Native. With Kotlin/Native it is possible to write code for many OS like Windows, Unix and MacOS. But Kotlin/Native can also be compiled to iOS, C or Obj-C bytecode. Like Kotlin/JS in 2017, Kotlin/Native will need some more time to be fun to use.

On top of targeting multiple platforms with different projects, Kotlin is offering multiplatform-projects to extract code into a common module. Let’s have a look at an open source Kotlin multiplatform-project to give you an idea of what that means. D3.js is a well-known JavaScript library to visualize data in diagrams and charts. The project data2viz (https://github.com/data2viz/data2viz) wanted to create a library with the same capabilities which can be used on multiple platforms. Currently they are targeting JavaScript for the Browser, JavaFX for Java Applications and Android. They are also working on iOS and will release it soon. Including iOS, the project has five modules. A Kotlin/JS module to target JavaScript, two Kotlin modules to target JavaFX and Android, a Kotlin/Native module to target iOS and a Kotlin common module which contains the shared code. In the platform dependent modules is everything that is relying on native functions. For example accessing the UI-Elements or calling system functions. Everything else is placed in the common module. It turnedout that more than 95% of the codebase is placed in the common module. So the idea of sharing everything that is possible to share and using Kotlins interoperability for everything else is working surprisingly well.

Bound to Gradle and ItelliJ

There are two conditions to use Kotlin properly that somebody may consider as a problem. The first one is that you should use Gradle as your build tool. If you didn’t prefer Gradle yet, here are some Gradle news. Gradle will release version 5 soon and eliminate two major pain points with it. It will decrease build times via build caches. And even more important, it will introduce Kotlin as its second first class language (besides Groovy) for the build scripts. That will bring features like code completion, type safety and even code inspection of Gradle functions to your build script.

The second condition is that you should use IntelliJ or AndroidStudio as your IDE. Those IDEs are from Jetbrains, Kotlin is also from Jetbrains – nothing to add. Those IDEs are really good, but still somebody maybe don’t want to use them.

The growing ecosystem

Regarding the time span of two years since its release, Kotlin has gained huge backing in our industry. One year ago Google announced Kotlin as its second first class language to develop android besides Java. Today already every fourth app (out of the top 1000) in the Android app store contains Kotlin code. And if the adaption doesn’t stop there will be more new apps written in Kotlin than in Java at the beginning of next year. In 2018 Google and Kotlin created the Kotlin foundation (https://kotl.in/foundation) to promote Kotlin even further and secure its open source status. With 70% of the developers using Kotlin for Android, Android is clearly the most related topic to Kotlin. But also 50% of the developers are using Kotlin for backend services and even 30% use it for web applications (was a multiple choice question).

Microsoft is converting some of their SDKs to Kotlin and they use Kotlin for desktop and mobile applications. Spring announced Kotlin as second first class language besides Java at the beginning of 2018. GCP (Google Cloud Platform) introduced a community project to open their services for Kotlin applications (ignoring the fact that you can deploy your Kotlin application anyway as a Java application). Some big finance institutes with millions of transactions write their backend services in Kotlin because of its performance. Another big player is moving its Frontend to Kotlin/JS while Kotlin/JS was just released a year ago. And there are many more companies like Netflix or Atlassian who are already using Kotlin.

A good indicator for the adoption is that the job offerings of companies who are looking for Kotlin developers had doubled in the last year. Some companies also use those offerings to get talented developers, because many good developers would like to work with Kotlin.

Summary (TLDR)

Kotlin has much to offer and that is realized by more and more people and companies. But regardless all those things there is one number I really like: over 90% of the developers working with Kotlin are satisfied and happy with that language. Maybe you could be the next one.