Kotlin is a new(ish) programming language from JetBrains, the makers of great IDE’s, one of which is the basis of Android Studio.
Kotlin was initially seen mid-2011 and became open source in February 2012. The official v1.0 was released early 2016 after it had been growing for 5 years.
It aims to replace Java for developers and promises to be quicker to code and completely interoperable with Java.
Within the last few months, there has been a lot of buzz, particularly in the mobile industry, about Kotlin. This may seem slightly strange, given that it has been around since 2011.
So why, all of a sudden, has it seemingly taken off?
The catalytic moments appears to be Google IO 2017. That’s where the Android team announced ‘first class support’ for Kotlin across the board.
This includes full IDE support and all the other great stuff that we have come to expect from Android.
This has resulted in a lot more developers taking a nose around the language (including myself).
Why should we care, as Android and Java developers, that a new language has surfaced?
For starters, as Kotlin has been around the block already, it is less in its infancy than one might expect. It has been brewing for 6 years now, with the benefit of an open source community behind it.
So, it is much further on than say Swift 1.0 was when that was introduced to developers. This means a stable language that is ready to use now.
Since Kotlin compiles to JVM bytecode, JetBrains have been able to make Kotlin completely interoperable with Java.
This is fantastic news as it means there is no cost to switching to Kotlin on your projects.
It also means you can convert any Java class into Kotlin with next to no pain, and actually, that is a great way to learn Kotlin.
If you are using a JetBrains based IDE there are some great converting features, including on the fly copy and paste.
Another fantastic side effect that comes with interoperability, is that you don’t have to go out and find/write a bunch of new libraries. You can still use all those libraries and frameworks you have come to know and love.
Kotlin focuses on being a great language and doesn’t enforce any particular development pattern, meaning you can carry on with your amazing (or terrible) architecture.
However, it does offer developers better defaults for normal code practice.
For example, you have to choose to make a variable optional (i.e. can be null) rather than everything being optional.
This forces developers to have to decide what null really means in that context, making your code less prone to silly null pointer exceptions.
In a similar vein, it offers much clearer ‘final’ variables with val vs var and classes default to being final.
Kotlin has a whole ton of features which one might expect from a modern programming language including:
Whether or not to switch to a new language is a difficult decision to make. Especially seeing as none of us like to be at the bottom of the ladder again.
Recently I wrote my first little app in Kotlin and absolutely loved it. It felt so familiar as a Java developer and was quick to pick up. It didn’t really feel like a new programming language but rather an adjusted syntax on Java. The only thing that took some getting used to was lambda’s since I haven’t used them yet in Java.
I feel that Kotlin will make development faster and code more safe and reliable. There is little overhead in adopting Kotlin and big names (including Android) have already done so. Therefore I see no reason to wait to jump onto this amazing train.
Go check it out at kotlinlang.org and give it go on your next project.
Caveat - Android Studio 3.0 has not yet released to stable. 3.0 introduces proper Kotlin support.
Check out Alistair's other musings on all things Kotlin:
There's testing for multiple platforms here
Pinning a certificate for iOS here
Coding and culture in Kotlin here
Or perhaps you'd be interested in strategies for multiplatform project structure here
Search over 200 blog posts from our team
Subscribe to our monthly digest of blogs to stay in the loop and come with us on our journey to make things better!