Kotlin: The Next Great Thing for Android Development

One of the many benefits of working at ISE is the diversity of projects our team members are working on. Whether it be a project for work or just some tinkering at home, the people at ISE have experience with a wide variety of tools.

As the Mobile/Web Project Lead, my responsibilities include keeping up to date with the emerging technologies in the market, and learning how we may be able to leverage new tech in the future. One such technology I have been hearing a lot about lately is Kotlin. I caught wind that one of our team members (Griffen Clark) has been tinkering with Kotlin on a few home projects, so I figured I would ask him some questions and share the knowledge I gain in a blog post.

Zach: What is Kotlin, and why was it created?

Griffen: Kotlin is a statically-typed programming language created by JetBrains. It is interoperable with Java in the JVM (and also Android Runtime environment), so the language can be used in conjunction with Java. Java can talk to Kotlin objects, Kotlin can talk to Java objects.

The language was created to enable Java platform applications to use a state-of-the-art language without any extra compilation overhead, contrary to other JVM-based languages, such as Scala. Kotlin does not only have to exclusively be used in a JVM environment. Kotlin can be transpiled to Javascript to be used in JS web applications. The people at JetBrains are currently working on an official release of Kotlin/Native, which can allow Kotlin code to be compiled to native binaries, ultimately enabling cross-compilation to other environments such as iOS. An official release for Kotlin/Native has not come out yet, but "experimental" releases can be used today.

As to why Kotlin was created, the creators of Kotlin have stated that there simply wasn't a language that met their needs of developing in a JVM environment. Scala was closest to what they wanted, but the slow compilation overhead killed productivity, so they decided to create their own language to solve this problem.

Zach: What makes Kotlin unique compared to the multitude of other programming languages out there?

Griffen: I think the biggest thing for me that makes Kotlin stand apart from most other languages is that its incredible conciseness allows us to drastically reduce boiler-plate code. For example, if you wanted to create a simple data object in Java with a few properties, that would typically be 40-50 lines of code with the correct method overrides you must do to make it a true data object (i.e. the equals() and getHashCode() methods). The equivalent code in Kotlin can take just one line of code.

Another thing is that because of its interoperability, Kotlin makes it easy to gradually change a JVM-targetting code base to Kotlin. This allows any projects that may have tons of legacy code in Java to be dynamically converted to Kotlin, and it's not an all-or-nothing switch. Java interop isn't anything new, as it can be accomplished with other high-profile languages such as Scala or Groovy, but as stated previously, Kotlin's concise syntax and fast compilation time arguably places it ahead of its counterparts.

Zach: When it comes to developing Android applications, what advantages does Kotlin give over Java or hybrid apps?

Griffen: Like I mentioned before, the cutting down of boiler-plate code is a huge advantage for me in terms of minimizing your application's footprint. For example, there is no more need for using Butterknife as a framework to cut down on front-end code with endless calls to "findViewById". Using the Kotlin Android Extensions, you can simply access Android views by their ID, and the compiler understands that this access by view ID indicates that the ID is in reference to a view object, and "behind the scenes", a view object is created and cached.

Android Studio also provides fantastic support for developing in Kotlin by integrating the Kotlin plugin with its official release of Android Studio 3.0. This enables great features such as automatically converting Java to Kotlin, decompiling Kotlin-originated bytecode to see what its Java implementation looks like, and fully utilizing Kotlin's powerful compiler within the IDE, showing you warnings when you can use "smart casting" or unnecessary null checks.

As for Hybrid apps, such as Xamarin-Android, I think it really comes down to preference. I will admit that I have more experience with Xamarin and C# as an Android Developer, and I've really grown to love C#. But since getting started with Kotlin, paired with my love for Android Studio as an IDE, I have been converted when it comes to writing Android applications.

Zach: Typically, advantages also come with disadvantages. For instance, hybrid applications typically enable code portability across platforms while sacrificing performance. What disadvantages have you seen from using Kotlin?

Griffen: To be honest, I haven't found too many disadvantages for me to second guess Kotlin and look for other languages that can do it better than they can. The only thing that may stand out as a nuisance to developers is how Kotlin tries to eliminate Null Pointer Exceptions by making it as annoying as possible to deal with nullable types.

By default, all types in Kotlin are non-nullable. You can make them nullable by adding the "?" symbol at the end of the type declaration, but then once you create an object and declare it as a nullable type, you must always use null-safe accessors or non-null asserted operators with the object. This can become a headache for developers who may be dealing with legacy Java code where every method might return null, but through dynamic transformation of the legacy code to Kotlin, null and NPEs can be a thing of the past.

Zach: Even though Kotlin was open sourced back in 2012, JetBrains appears to be continuing to invest and support the language. What are some of the interesting and/or innovative features that are coming to Kotlin in the future?

Griffen: Well, just a couple weeks ago, the Kotlin 1.3 release candidate became available which brought some very anticipated new development to the language. One of which is Coroutines, Kotlin's library for handling asynchronous code. Up until the 1.3 RC, the coroutines library was meant to be used experimentally, as it was still in development. Now with 1.3, there is full support of the coroutines library, with potential updates as it is a release candidate.

The previously mentioned Kotlin/Native also just went beta, which is very exciting for developers using Kotlin to target different platforms. Ktor, an asynchronous web development framework for Kotlin that is being developed by JetBrains, has not hit an official 1.0 release yet, but once it does, it could be a huge hit with the web-dev community.

The future of Kotlin is very exciting, and they are quickly working towards their mission statement of being able to use Kotlin on any platform.

Zach: You have me interested, what’s the best way to get started learning and developing with Kotlin?

Griffen: If you're a developer who wants to just dive in and get your hands dirty, I recommend cloning the Kotlin Koans repository which is a great collection of coding exercises that will get you comfortable with a lot of the basics of Kotlin. You can also do these exercises online.

If you're interested in just learning about Kotlin from a higher-level perspective, I recommend checking out the "Introduction to Kotlin" presentation at last year's Google I/O, or their presentations that were recently held at KotlinConf 2018 to learn all about the latest news on Kotlin.

Special thanks go out to Griffen for helping me get a firm understanding of Kotlin and where we may be able to use it as a company. It’s exciting to learn about the people and skills that make ISE a special place to work. Interested in joining our team and learning new technologies? Learn about our current opportunities on ourCareerspage!

Between matches of ping pong in the break room, Zach Bodenteiner is a Senior Software Engineer, SME of Mobile Development, and Team Lead at ISE. He graduated from the University of Iowa with a degree in Computer Engineering in 2012, and joined ISE shortly thereafter. When he is not growing his skills at the office, he can be found participating in local pub trivia, doing yard work/gardening or playing with his dog, Millie.

Posts by Topic

ISE delivers innovative, end-to-end, scalable IOT and telematics solutions, enterprise mobility applications and tailored software solutions that help companies simplify and solve even their most complex business challenges.

ISE BLOG

Delivering Excellence, Providing Opportunities! Join a company with an award-winning culture where you can collaborate with the best and the brightest while working with emerging technologies! Join the ISE Team!