Subscribe

Why Kotlin?

By Pamela A Hill, Senior Java Developer at DVT


Johannesburg, 21 Feb 2018

Before the announcement of first-class support for Kotlin on Android at Google I/O 2017, not many had heard of the programming language that was suddenly stepping into the limelight. Kotlin 1.0 had been released only the year before, following many years of development by a team of JetBrains developers based in Saint Petersburg, Russia.

Why did Google decide on such a relatively unknown language to join giants Java and C++ in first-class support? Will it become widely used elsewhere, such as server-side and the Web?

This article will touch on a few key points on why Kotlin is a great language worth learning, and ultimately using, in production, says Pamela A Hill, Senior Java Developer at DVT.

Kotlin supports more comprehensible code

Comprehensibility, not conciseness, should be used as a measurement of how good a programming language is. We spend so much time reading code, not for its own sake, but rather to understand it. Kotlin supports writing more comprehensible code in many ways. For example, data classes are like POJOs (plain old Java objects), but the accessors, mutators, equals, hashCode and toString methods are implied. Therefore, these methods do not have to be written/generated, tested and maintained. Another example is named arguments, where the programmer can be explicit about which argument is being specified. Calling legacy code, which often have lengthy parameter lists, using named arguments can clarify code significantly.

Kotlin is interoperable with Java

Java code can be called from Kotlin, and Kotlin code from Java. This provides Kotlin with the Java ecosystem of frameworks and libraries. The developers of Kotlin have also made the smart decision to use the Java collection framework, rather than create their own. In terms of interoperability, this means that no transformation between Kotlin and Java collections is necessary. Motivated to overcome the shortcomings of the Java collections, the developers of Kotlin provided the ability to create extension functions for any class, which can be called as though it formed part of the original class.

Supporting safer code

Kotlin supports writing safer code - code that is naturally less buggy. It is a statically-typed language, so the compiler will pick up errors before the code is even run for the first time. Kotlin forces you to think about null values very carefully. If a variable could possibly be null, you are forced to declare the type as nullable and handle the null case wherever the variable is used.

Kotlin encourages you to think about mutability versus immutability, with idiomatic Kotlin favouring immutability. Kotlin limits the extension of classes by making classes final by default and allowing for explicitly restricted/sealed hierarchies, thereby ensuring sub-classes are not inadvertently allowed to break contracts.

A modern language

Kotlin is a modern programming language. It is object-orientated, but also allows top-level functions and constants to be declared without the need for irksome utility classes. Kotlin allows for functional programming, with lambdas and higher-order functions.

Excellent tooling

Kotlin has excellent IDEs (Integrated Development Environments) available from JetBrains: IntelliJ Idea and Android Studio. At the time of writing, there is also an Eclipse plugin and Emacs mode available for Kotlin. The JetBrains IDEs have Java to Kotlin converters, which can be significant timesavers and often only require minimal checking and clean-up. They also have handy suggestions to help you on your journey towards writing more idiomatic Kotlin.

Share

Pamela A Hill

Pamela A Hill is a second-generation programmer and holds a BSc IT and BSc (Hons) Computer Science from the University of Pretoria. She has many years of experience writing desktop, Web and mobile apps. Her other interests include UX (user experience) design, and theology - she is completing a BTh with SATS, psychology and the arts. You can get in touch with Hill on LinkedIn: https://www.linkedin.com/in/pamelaahill/

DVT

DVT is a software development and testing company that focuses on digital transformation technology solutions for clients globally. Its services include custom software development for mobile, Web and traditional platforms, software quality assurance, automated regression testing, UX/UI design, cloud application services, DevOps consulting and data and analytics solutions, as well as agile training and consulting. Founded in 1999, DVT has grown to over 700 staff, with offices in the UK (London) and South Africa (Johannesburg, Centurion, Cape Town and Durban). Visit DVT at www.dvt.co.za www.dvt.co.uk.

Editorial contacts