Reg comments14

Hello, Kotlin: Another programming language for JVM and JavaScript

New 'pragmatic' open source language developed by JetBrains hits version 1.0

JetBrains has released version 1.0 of Kotlin, an open source programming language for the JVM and Android.

Why Kotlin? JetBrains is a developer tools company whose IntelliJ IDEA IDE has been adapted by Google for Android Studio, and the short answer seems to be that the company wanted something better than Java with which to build its own products.

Most of the JetBrains tools and IDEs are cross-platform and run on the JVM (Java Virtual Machine). According to lead language designer Andrey Breslav, there are already over 500,000 lines of Kotlin code in JetBrains products including IntelliJ IDEA and the new Project Rider, a C# IDE.

Breslav describes Kotlin as pragmatic. "For us pragmatism is about creating user experience, not a language or a library alone," says Breslav. "The primary goal is being useful." Therefore, Kotlin is interoperable with Java, compiles to Java 6 byte code, runs everywhere Java runs from servers to Android, and uses existing Java tools for its package management and build system.

Kotlin can also target JavaScript, joining many languages and tools with this capability, including Google Dart, Microsoft TypeScript, and Google's GWT (Google Web Toolkit).

In what way is it better than Java? According to its official FAQ, Kotlin is a statically-typed object-oriented language whose goals are to compile "at least as fast as Java", to be safer than Java by checking for "common pitfalls", to be more concise than Java by including features such as type inference, closures and extension functions, and to be more expressive, "making it way simpler than the most mature competitor, Scala."

Unlike Java, Kotlin has no primitive types that are not classes. Feature in Kotlin but not in Java include Lambda expressions, template expressions in strings, properties with getters and setters, and operator overloading.

The language designers have also tried to eliminate null references from code. British computer scientist Tony Hoare says he invented the null reference in 1965 but that it was "my billion dollar mistake". A null reference is a variable that is declared but either has no value, or has been specifically set to null. When code then tries to access that variable, you get errors such as Java's null pointer exception, or a dialog familiar to Visual Basic and .NET developers, "object reference not set to an instance of an object."

Kotlin tries to avoid null reference errors, by having types that are non-nullable where possible, and allowing safe property access with the ?. operator, that returns null rather than raising an exception if the object is null. If you try to access a property directly on an object that may be null, the compiler reports an error. Nevertheless, you can still raise null property exceptions if you explicitly code to allow them.

Is Kotlin likely to be widely adopted, given the extensive competition? A discussion on Hacker News is broadly positive. "I've been following and experimenting with Kotlin now for the past year or so and it definitely solves a lot of Java's pain points without having to reinvent the way one thinks about programming languages," says one developer. "This is an amazing replacement for Java on Android and hope it gets more public recognition," says another. Getting the necessary momentum will be a challenge though. "It feels a bit early for a release however. The compiler is still completely wonky," says another otherwise enthusiastic early adopter.

Java compatibility means there is nothing to stop developers switching to Kotlin if they like it, but to get real traction it will need to attract usage from a major Java user such as Google, which already has home-grown alternatives. ®

Sign up to our Newsletter

Get IT in your inbox daily

Biting the hand that feeds IT © 1998–2017