Trōv has been using Java since the beginning when it comes to Android development. Java is great but Kotlin offers new, more modern features that we just couldn’t resist. Trōv is starting to use Kotlin to build our Android applications.
Trōv wasn’t specifically looking for another language. We were quite content with Java but we couldn’t deny some of the pain points that came with developing in Java. Among the list, boilerplate code is a big one and verbosity is a close second. The lack of native lambda support in older versions continually challenged us. Without using third party libraries, that wasn’t possible. Don’t get us wrong, we love third party libraries and we try to support them, but pure native language support is even better.
Clean and explicit code is extremely important to us and Kotlin’s built-in support for null safety helps avoid those null pointer exceptions. Dealing with this problem at the language level is very helpful. Kotlin enforces this explicitness and also reduces the chance of introducing nulls. This allows us to move faster, reduces the amount of bugs and also makes the code easier to understand.
Another useful feature of Kotlin is the support for higher-order functions and lambdas. A higher-order function is a function that takes functions as parameters or returns a function. This is helpful and with native lambda support, it makes code seamless to read. Those two features together drastically reduce the amount of code we need to write. With less code there is a smaller chance of introducing a bug. Lambdas make the code lean and concise. This is not true of the anonymous class, which is the Java counterpart. Here at Trōv, we’re grateful for lambas when using RxJava.
A small but extremely effective feature in Kotlin is the support for data classes. When you're writing a lot of classes that simply hold data, it comes with overhead. You need to maintain equals, hashcode and toString every time you modify your classes. With data classes, you get all of these goodies for free.
Kotlin solves the utility class problem we’ve always had in Java using function extension. Basically, it allows us to extend a class’ functionality without the need to use inheritance or any type of patterns, such as the decorator pattern. This is powerful because we can now expand on the functionality of the string class - something we’ve done many times using a utility class. We no longer need to call static methods from our utility classes which in turn give us more idiomatic code and improves readability.
Most libraries we’ve developed for Android or consume externally have all been written in Java. If we were to consider any other language to develop Android, it would have to completely support Java. Kotlin is 100% interoperable with Java. This is huge! For example, we now have a new language we can use in only part of our app and have it interoperate with our original code. We don’t have to settle for all or nothing. This makes Kotlin undeniably attractive.
By using Kotlin, Trōv will be able to ship code that is higher quality and we’ll be able to do it in a much shorter timeframe. Because Kotlin does such a great job at simplifying everything, we have more time to focus on delivering features and value, and will spend less time working around the language itself.
While Kotlin's features make coding faster, there are a couple of limitations we needed to consider. There is a lack of defined patterns establishing how to use and how not to use Kotlin. And there are very few static analysis tools available. With that being said, however, the value we are getting from Kotlin outweighs these limitations, as they won’t be problems for long.
Now that we’ve decided that Kotlin is a language that will benefit Trōv, we’ve formulated a plan to help us learn and integrate more Kotlin in our Android development process. We’ll share our approach to the integration process in an upcoming blog post.