Kotlin is a programming language developed by JetBrains Company. The name of the language comes from Kotlin Island located in the Gulf of Finland. The development of the language began in 2010. On June 2012, milestone 2 with the support of Android was released. Since 2017 the official tool for the development of Android OS, Android Studio 3.0, will include the Kotlin tools based on IDE by JetBrains.
Kotlin is marketed as object-oriented language. It is claimed that this language can be a substitute to Java. Like any programming language, it has its supporters and haters. Let’s find out the pros and cons of using Kotlin for the development of Android applications.
Pros of Kotlin for Android development
- Open source. You do not have to pay for adopting Kotlin, since it is an open source language.
- Kotlin is a practical rather than theoretical solution. This language avoids many practical issues faced by most developers.
- Java compatibility. If you need to convert Java to Kotlin, you can use a simple converter tool. Even the existing project based on Java can be easily converted into Kotlin and no line of code will be broken. In addition, all existing Java libraries and frameworks are available in Kotlin and can be applied. You do not need any adapters or wrappers.
- Simplicity. It is not a problem for a developed to learn this language in a few hours. It reminds Scala a bit, but is has intuitive and lean syntax. It is fast to write, easy to read, and the code is very compact. Besides, Kotlin has an integrated error protection.
- Null Safety. This feature marks variables that can be nullable. Most of the languages do not provide such option. There is no need in traditional workarounds if nullability is available in the type system. This feature is especially important on Android, while its garbage is too sensitive to tiny objects.
Kotlin language exceeds Java in many features, however, it has the following significant flaws.
Cons of Kotlin for Android development
- Slow compilation. You will spend around 1 minute to compile a small project for approximately 100. This is rather slow if compared to other languages.
- Poor performance of IDEA plugin. Development machine is often frozen by Kotlin analysis of syntax in IDEA.
- Annotation processing issues. Random errors regularly emerge requiring cleaning function. Unfortunately, many developers complain about this drawback.
- Mocking Kotlin classes. Regardless of the fact that Kotlin provides finalization of methods, classes by default, mocking via Mockito requires changing code for testing. If compared to Java that has everything non-final, it is not a huge problem, but some developers may not understand such mocking solution.
- Kotlin has no static analyzers. Analysis of static code is good for CI, however it is initiated every time you click on “Run” button. Static analyzers are required to achieve good performance of the compiler.
This rather new name in Android App development is already winning its popularity among the developers. The main feature of Kotlin is its similarity to Java, which does not require new specific knowledge, and the developers who are not familiar with this language can review code without any problems.
Here are some quotes from companies, that already involved Kotlin in their projects and some developers all around the globe.
Dan Kim from Basecamp
“We started our Kotlin journey a year ago based on two hunches: that it would
1) make a huge difference in programmer happiness
2) wildly improve our work quality and speed.
I’m happy to report that our hunches were right! As of the end of April, Basecamp 3’s Android app is written in 100% Kotlin.”
Kristina Lee from Pinterest
“It is hard to argue that Kotlin is not an amazing language. What is easy to argue is that there are many unknowns about its performance in the wild and at scale, which makes it hard to make an informed decision about incorporating it into your app. After more than a year of maintaining a pure Kotlin app at Highlight, and more recently helping Pinterest ramp up Kotlin in Android, we’ve learned much about the ramifications of moving away from Java.”
“I want to explain why I prefer Kotlin over Java.
In short, the many myriad Kotlin features enable more concise and understandable code than Java without sacrificing performance or safety.
Kotlin compiles to bytecode, so it can perform just as well as Java. It’s got the same compile-time checks as Java (and more, such as built-in nullability checks). And most importantly, Kotlin’s language features and standard library functions enable succinct, effective code.”
“I used to prefer Java but the last year I’ve found myself coding Kotlin whenever I could, and at this point I really can’t think of a situation where Java would be a better choice.
It’s developed by JetBrains, and the fact that these are the people behind a suite of IDEs, such as IntelliJ and ReSharper, really shines through in Kotlin. It’s pragmatic and concise, and makes coding a satisfying and efficient experience.”
“Kotlin is a new programming language from JetBrains, the maker of the world’s best IDEs.
After much searching, I have settled on it as the programming language I will probably use for the next 5–10 years or so. I like Kotlin a lot and think it will be a very successful project.”