Kotlin: A Powerful New Android Programming Language

Android mobile app development is being shaken up by a newcomer – the Kotlin programming language – which in a few short years has gained enormous attention along with a small but growing share of the language market.

Kotlin was first officially released in February 2016 by JetBrains, the company behind IntelliJ IDEA, the heart of Android Studio, the tool used for most Android mobile app development. Less than two years later Google announced official support for Kotlin on Android at Google I/O 2017, and as of the release of Android Studio 3.0 a few months later, it is now built into the development toolset, officially making it a first-class Android language. It has made inroads into a lot of high-profile companies, including Amazon Web Services, Evernote, Pinterest, Coursera, Netflix, Uber, Square, Trello, Basecamp, and others.

Benefits of the Kotlin Programming Language

Kotlin proponents say there are several core reasons for its burgeoning success:
– It is safer and more concise than Java (currently used for most Android app development)
– It interacts seamlessly with Java, and can be plugged into existing Java-based apps
– It is very quick for Java developers to learn

Concise: Its supporters like to boast about its “lean syntax” – some estimates show a cut of about 40% in the number of lines of code to accomplish the same things.  Its syntax is not as complex as Java’s, and is sometimes described as “Java Light.” This makes it easier for programmers to read and therefore review and debug code, saving time.

Safe: One of the big hassles of programming in the Java is the need for a great many “null checks,” making sure that a resource isn’t null or undefined before attempting to access it. Kotlin was designed to eliminate a common error called a “null pointer reference,” and allows programmers to avoid verbose checks.

Seamless: Kotlin files be dropped directly into existing Java projects, making for low-risk adoption. Tools exist to convert Java files into Kotlin files so entire projects could be Migrated fairly quickly and easily.

In addition to the above, Kotlin’s big advantage – emphasized over and over – is its simplicity and removal of the boilerplate necessary for Java. Kotlin’s “type inference” eliminates the need for verbose definitions. It basically does a great many things behind the scenes so developers don’t have to worry about them. Chief among them:
– Extension Functions – These are essentially “global” functions shared across multiple classes, defined in the function declaration. This takes the place of the utility classes that can be found in almost any Java project.
– Implicit view binding – Android developers are all too familiar with the difficulty of accessing layout views through the “findViewById” call or binding libraries such as Butterknife. But Kotlin Android Extension automatically create accessor variables for all views in a given layout. Just call it by name and there it is.
– Collection simplification – Kotlin allows vastly simplified data object collection definition and filtering, and in some cases a single line of code can perform a series of operations that would take a dozen lines in Java.

Downsides of the Kotlin Programming Language

There are downsides, of course. While the new syntax is easy for programmers to learn, becoming truly familiar with the ins and outs of a programming language always takes time. And because of its relative youth, there is as yet no standardized code style, and the support community and programmer pool is still small. Other more detailed shortcomings are:
– No type aliases yet, so function types have to be written out every time
– The IDE plugin still throws exceptions more than it should
– Some Java frameworks don’t deal well with Kotlin defaults, so they need to be explicit
– Because of compile-time function inlining, stack traces can sometimes get messed up
– Compiling through gradle is slow
– It works best on IntelliJ – not so great on Eclipse
– It’s pickier about some things than others. It will not auto-convert ints to longs, etc.

Despite these downsides, the fact that it originated from industry instead of academia and is supported whole-heartedly by an established company at the heart of Android development means it is both robust to use and not likely to go away any time soon.

If you like hearing about new technology and other innovations impacting mobile strategy, sign up for our monthly newsletter.