Obsessed with technology?
Subscribe to the latest tech news as well as exciting promotions from us and our partners!
By subscribing, you indicate that you have read & understood the SPH's Privacy Policy and PDPA Statement.
Feature Articles

Kotlin: Developing Android apps swiftly

By PY Ho - 21 Aug 2017


For any platform, buy-in from developers is key to its success. Android became a huge success mainly because developers embraced its proposition and develop apps/mods for the Android platform. Among several other factors that fell in line to propel Android's popularity, one key factor towards winning the developers mindshare was the choice of programming language adopted: the more developers are familiar with a development language, the higher the chances of success.

For Android, up till Google I/O 2017, the only official language support is Java (there is also lower-level language support for C++ but that is for specialized purposes). When Google announced that Kotlin will officially be supported in Android, many developers were overjoyed, as they have been waiting for such an announcement for a very long time. Just what is Kotlin? Why it is a favorite of Android developers, and what are the implications for consumers of apps?


Kotlin, the Swift of Android

To summarize what Kotlin is in one sentence, Kotlin is to Android just like how Swift is to iOS. However, the only similarity between the two languages is the programming paradigm - they are designed to make development easier and safer (for the developer, that is). In technical terms, Kotlin is a Java Virtual Machine language - not Java per se, just that the code can run on a Java intermediary. It is designed to improve the shortcomings of Java:

  • Less boilerplate, repetitive coding

“Boilerplate coding” is when the developers have to repetitively code a pattern just to get things done. In Java, coding is often verbose. In Kotlin, much of this boilerplate coding is reduced. Other features, such as lambda expressions and extensions, reduce the verbosity of coding for developers and is supported on Kotlin.

Left: Kotlin. Right: Java. Even a layman would agree that Java is too verbose and laborious.

In addition, the flexibility of the Kotlin language allows more varieties of expression when developers code. In the traditional way of Android development, developers have to explicitly and statically define view elements in a separate "view" file (an XML file), then make explicit reference to those elements in the Java code, before they can actually do something about it. In Kotlin, they have choices: either use Kotlin Android extensions, which allows them to reference from the XML file directly, or even do away with the XML file altogether and directly define the views in the Kotlin code itself.

  • Safe programming

In programming, one of the biggest problems is encountering unexpected null values. Null values are simply values with no meaning, not even zero. It’s like an answer to the question - "I have a bag of apples. I took out half of the apples. Count the number of apples I have left." The answer’s undefined, meaningless, it can be anything and it can be nothing - similar to a null value. Yet, developers often make such mistakes of assigning null values. Assigning meaningless values within the app results in crashes. The design of the Kotlin language forces developers to proactively confront this problem, failing which, the code will not compile.

  • Co-existing with existing Java code

Though Kotlin is a different language, it is designed to interoperate with existing Java code. Developers need not convert their existing code to Kotlin, in order to start coding with Kotlin. 


Implications for consumers

  • Faster app updates, new apps get pushed quicker

By reducing the number of lines a developer has to write, developers can get their app published faster from zero. With that, consumers can expect a greater variety of new native apps published in Google Play.  

Also, developers of existing native apps can update their apps at a faster pace. Consecutively, consumers can expect speedier updates from developers making the switch to Kotlin.

  • Less 'crashy' apps

Ever get the "App is not responding" prompts when you use an Android app? More often than not, they are caused by the encounter of null values in the app. By forcing developers to confront and deal with null values, users will experience less app crashes.

App Not Responding (ANR) prompt when a beta app crashes. Forgivable for betas, but should not happen in official releases


However, the introduction of Kotlin probably has little effect on developers who are already using cross-platform tools to develop Android (and iOS) apps. These cross-platform toolchains each have their own programming language built on top of the native Android platform, hence the advantages of Kotlin is moot in this workflow. In local context (Singapore), there are a significant number of apps that are developed using cross-platform tools.
While Kotlin does help developers produce quality apps, it only helps those that are already developing natively. With the number of cross-platform apps in the market, it remains to be seen whether Kotlin can raise the standard of quality Android apps from an overall perspective.