The advantages and disadvantages of Kotlin in Android application development
A blog by the iCapps Android team
A few weeks ago, at its annual I/O Keynote, Google announced that it will be offering full support to Kotlin as an official programming language for Android development. Kotlin, which runs on the JVM (Java Virtual Machine), has been around since 2011 and has been a popular language for Android development for quite some time. But this official support from Google will no doubt give it a further boost!
So what makes Kotlin popular? What are the advantages and disadvantages of Kotlin over Java in Android application development? Should we all start using it more? Is it difficult to learn? We asked our Android developers these questions. Find out their Yays & Nays and their final verdict in this blog!
Yay to Kotlin
- Kotlin code is short and clean. Moreover, the basics are very similar to java, which makes Kotlin easy to learn if you know java.
- Kotlin is 100% interoperable with Java. You can use both Java code and Kotlin code in the same project: Kotlin code can be called from java, and vice versa. And all java and Android libraries can be used in a Kotlin application.
- Kotlin has a bigger community than Java. Kotlin has a lot of traction: it is used by large players – think ofJetbrains (formerly intelliJ), Square and Google. And if you’re looking for a job, making sure your Kotlin skills are top-notch is not a waste, since it is becoming a much sought-after skill in Android developers.
- Kotlin entails minimal risks. It is stable, and mixing it with java makes sure that any problems which arise can be solved in java.
- Kotlin is supported by all major Java IDEs, including IntelliJ IDEA, Android Studio, Eclipse and NetBeans. It has debugger support, Java files can automatically be converted into Kotlin, and you can build Kotlin with Gradle, the Android Build System. (Interesting to know: Kotlin was developed by Jetbrains, the creators of IntelliJ IDEA, the Android IDE.)
- Kotlin offers some interesting language features.
- The built-in null system reduces the chance of NullPointerExceptions and renders contrasts between classes visible.
- Lambda expressions are supported on older java runtimes (java 6 and beyond).
- It has a better generics systems (templates), whereby type information does not get lost.
- Other interesting features: delegated properties, lazy loading, and DLS creation; it gives you “simple” dependency injection; classes are non-extensible by default; it supports extension methods AND extension properties.
Nay to Kotlin (but with some “but’s”):
- The language semantics have some drawbacks: The static methods work differently (But: this has no impact on the final execution.), and classes are by default not-extensible, which makes testing harder.
- The Kotlin IDE plugin is at times unstable. (For example, we saw some delays in code completion, occasional exceptions.)
- Kotlin StdLib contributes to the method count (This is important if you do not want to work in multidex.). There are 6317 methods for the StdLib and 11423 methods for the reflection library. By way of comparison: the Android support libraries count 23661 methods
- Compilation takes a bit longer. (But: incremental compilation is getting better and better).
So what’s our Android developers’ final verdict?
“The pros outweigh the cons, so I would definitely use it in new projects.” – An iCapps Android dev
“Let’s get rid of java and write all future projects in kotlin.” – Another iCapps Android dev
“Yes!” – Another iCapps Android dev
“The advantages offered by Kotlin’s semantics and its runtime convenience, together with its large community support, convince me to use kotlin for all future projects.” – Yet another iCapps Android dev