Kotlin: The Java Alternative
Since 2011, Kotlin has taken the developer world by storm, becoming one of the most loved languages. Endorsed by Google and used in many large organisations, it’s clearly gained momentum but is Kotlin worth looking into, or is it yet another craze over a language that will die in a couple of years? Should you invest time and money into adopting it?
One of Kotlin's greatest advantages is its interoperability with Java - the two can work together side-by-side in the same codebase with ease. Kotlin can leverage the extensive JDK libraries and utilise all the packages that have become available over the many years Java has been in existence.
It also ensures that you don’t have to change the world overnight. Looking at that legacy system that you can’t bin nor rewrite from scratch, Kotlin allows you to take each area and ‘translate’ bits as you come across them. So, in case Google announces that Java will no longer be supported for Android development, any old Android apps written solely in Java can be slowly migrated over to Kotlin.
Java is well known for the fact it requires a lot of boilerplate code, so when Jetbrains built Kotlin, one of their main focuses was to give developers their time back.
In Java, every class has to have its variables previously declared: you have your getters and setters, etc. Kotlin considers this and does the magic behind the scenes for you. So, instead of retyping the same thing repeatedly, you can spend time solving the problems that actually matter. Although it can take some time shifting from a Java “way of thinking”, when you do, it can make your life significantly easier. Jetbrains has also implemented a Kotlin file converter into their Intellij IDEA, allowing automatic refactoring of Java files into Kotlin with minimal effort - further aiding you in focusing on what really matters.
After Jetbrains’ V1 stable release in 2016, it only took Google a year before announcing official support for Kotlin in Android development. Not only has Jetbrains put a lot of thought, time and testing into the creation of Kotlin, their maintenance of the language is something to be admired.
They take into consideration the pain points raised by developers and, with fairly frequent updates, try to resolve those issues. This is in stark comparison to Java, which had been neglected for a few years before Oracle bought Sun, and in turn, became part of its downfall. This allowed languages like Kotlin to easily become a more favoured option.
Although Jetbrains has tried to make Kotlin as versatile as possible, Google’s support for it in terms of Android development has pigeonholed the resources available. Frequent questions and blog posts usually focus on the mobile usage of Kotlin.
However, it’s worth highlighting that Jetbrains’ documentation is superb and includes detail about use cases outside of just mobile development. With other frameworks providing official support (e.g. Spring), there is a significant amount of official documentation in a variety of use cases.
So although at first glance, everything seems to point to mobile, don’t let that deter you from creating something that is outside of that remit.
In comparison to Java, Kotlin is a young language. With new languages comes various complications: missing capabilities, lack of experience, lack of resources and the fear of it becoming unused soon.
Java, in contrast, is everywhere: most developers have, at the very least, touched upon it before. With Kotlin, the smaller pool of talent means hiring someone with expertise can be more challenging. You’ll likely have to consider the overhead that comes with learning a new language - especially with Kotlin having a different thinking approach to Java. Many developers write Kotlin in a Java mindset which, although perfectly functional, doesn’t leverage the language to its full potential.
It looks like Kotlin is here to stay: gaining traction and momentum every year with greater support from big companies worldwide. Flaws are being quickly fixed by Jetbrains’ ample support, and issues around the breadth of resources will inevitably reduce with time.
Having personally previously worked in Kotlin, it’s a welcoming language that’s easy to adopt. Particularly when approaching the language from a Java background, Jetbrains’ IntelliJ translation function, although not perfect, makes it easy to highlight the differences between the languages. It allows for a headstart when you might not be sure of the best way to approach a refactor.
As with any new language, there will always be people who adore it and people who want to avoid it as much as possible. However, it’s hard to ignore the benefits of Kotlin - and remember, the only way to know is to give it a go and find out for yourself.