Why you should start using Kotlin today

By 9 April 2020Uncategorized

Why you should start using Kotlin today

One of the newer and more prominent technologies we have nowadays is Kotlin; a programming language built to increase productivity when developing enterprise applications. For any (software) company, increasing developer productivity is one of the most important areas for improvement.

Building software faster, without compromising on quality, provides a remarkable competitive advantage in the market, which is why there should always be room for improvement throughout all layers of the company. Boasting many interesting key features, Kotlin seems to be on the right track to become more widespread across software producers.

At INFO, we have been using Kotlin for a while now, and because we believe it has matured enough in terms of popularity and adoption, and has had a significant impact on our development time, we thought it was time to share why it’s such a valuable technology to adapt within your company.

The popularity of Kotlin

There have been a number of Java Virtual Machine (JVM) languages introduced over the years, and while Java is the oldest of them, it is still the most predominant choice among programmers. However, despite the strong preference for Java, Kotlin had gained a lot of popularity over the last couple of years. According to the JVM Ecosystem Report 2020, the amount of Kotlin developers grew from 2.4% to 5.5%, and became the second most popular JVM language.

One of the reasons behind its popularity is the seamless Java integration, allowing easy adoption. Support from popular frameworks, such as Spring Boot, also makes it easier to create production-ready platforms. According to the same report, Spring dominates the Java ecosystem, with 60% using it for their main applications. Dedicated Kotlin support in the Spring framework has been introduced along with version 5.0, and the following statement from Spring’s official blog ensures that this partnership will continue to last: “In addition to Spring Framework support for Java 8 that Kotlin applications can leverage like functional web or bean registration APIs, there are additional Kotlin dedicated features that should allow you to reach a new level of productivity.”

In addition, Google has declared its full support for Kotlin, stating it is the primary language for native Android development. This statement has reflected positively within the professional Android development community, as more than 50% prefer Kotlin for their day-to-day work.

As Kotlin is fully interoperable with Java, embracing it becomes relatively easy for software development teams that are looking to move their codebase into Kotlin step by step, as well as using it for their next project. This leads to yet another reason why the popularity of Kotlin across software companies is increasing: a lot of big companies started to include Kotlin in their tech stack. Companies like Amazon, Google, Netflix, Uber, Foursquare and many more adopted the language remarkably fast and eventually gained young talents’ attention looking to be employed by them. When a technology attracts the attention of the big players in the software market, that influences the developers who are most likely to dive in and try out new languages, tools and techniques. And if it turns out to be better than what they worked with before, the choice is simple.

KotlinConf

KotlinConf 2019

The community of Kotlin has been very active and growing significantly. There have been around 200 user groups across the globe, which organize various events, key notes and workshops related to the Kotlin ecosystem. This community activity is actively being supported by the creators of Kotlin, JetBrains, who organize an annual global Kotlin conference, KotlinConf. For their latest edition, 1,700 people attended and tickets were sold out months prior to the event.

To sum up, as per the results of Stack Overflow’s annual developer surveys in 2018 and 2019, Kotlin has become one of the most-loved languages today and has been for two years in a row!

The impact on productivity

The reason why Kotlin works so well, is that the design of the language mainly focuses on being as productive as possible with a programming language. By taking inspiration from existing languages, Kotlin has a great feature set that reduces development time. They have put in a lot of work to make sure this feature set is highly accessible as well, rendering the learning curve relatively small. Let’s dive a little deeper by getting a bit more technical.

A good example as to why this has a significant impact on productivity is given during one of the talks of KotlinConf by Christina Lee; Testing: Testing (which we definitely recommend watching!). During this talk, Lee used a more detailed version of the famous test pyramid.

Test Pyramid

Detailed Test Pyramid by Christina Lee

This version has some extra layers below the cheap Unit layer, most notably compile-time and IDE errors.

Although these initially don’t look like tests, they can definitely be utilized as ways to enforce business logic in a rather cheap way. By using types, you enforce that code has to be run in a specific way: if you try to instantiate an object that isn’t expected, your IDE (or compiler) will tell you that something’s wrong. It’s inherently testing your code.

But typing isn’t new, it’s been around for a very long time. It is, however, part of one of the core principles of Kotlin: introducing safety. This is done by offering strong mutability rules through the usage of both Object-Oriented and Functional Programming, but most noteworthy: null safety. According to the OverOps research, the number 1 most seen exception in production systems is the infamous ‘NullPointerException’. Because of this principle, developers can spend a lot more time and focus on the compile-time / IDE error testing, which results in fewer NullPointerExceptions, which saves a lot of time.

Top10 Exeption Types

And it shows! One of the big ‘competitors’ of Kotlin is Java, as they both run on JVM. However, realizing the same type of safety within Java (when compared to Kotlin) requires a lot more code. Creating a simple Java data class with three fields would result in about 70 lines of code, consisting of a constructor, getters, setters and implementing methods such as ‘toString’, ‘equals’ and ‘hashCode’. In Kotlin, this same data class, including the methods/functions, consists of about five lines, achieving exactly the same without all the boilerplate. As said in the first chapter of the popular book Kotlin in Action: “More concise code takes less time to write and, more importantly, less time to read. This improves your productivity and lets you get things done faster.”

 

The next step

While the community support and productivity boost are nice, it’s not easy to actually evolve to Kotlin as a company; it’s not a case of simply flipping a switch and becoming ‘all Kotlin’ all of a sudden. However, we have thought of a couple of methods you can use to take this next step: 

  • Organize presentations and/or workshops, sharing knowledge and keeping everyone at the same level; 
  • Delegate Kotlin features to your team, making everyone an expert on a specific domain, allowing to share knowledge more efficiently; 
  • Create a resource base, documenting challenges you have faced (and overcome), and how to resolve or avoid them in the future; 
  • Rewrite your business logic, starting with your least-critical components, while using the written tests to make sure everything still works. In our experience, a good jumping-off point is starting with the data classes. 

The best stories about innovation?
Sign up for our newsletter!

Please leave your name and email below

Stay up to date

Sign up to receive valuable insights to accelerate your business through innovation.