New programming languages are created every year, but seldom do they gain the attention of developers like JetBrains’ Kotlin has over the last couple of years.
Kotlin is a general-purpose, statically typed programming language designed for the JVM, Android, browsers and native solutions. It was created by JetBrains’ language designer Andrey Breslav and officially announced by JetBrains in 2011.
Today, Kotlin has become one of the most loved languages on Stack Overflow, one of the fastest growing programming languages on GitHub, and the language of choice for Android application development. Kotlin has also been featured in this year’s Thoughtworks’ Technology Radar for its rise across platforms and tools.
“Developers who haven’t yet checked out Kotlin would be well advised to have a look at what it can do. It’s a genuinely good language with solid features and a growing ecosystem,” said Rebecca Parsons, chief technology officer at ThoughtWorks.
But why and how has Kotlin captivated so much interest from developers in such a short period of time? For starters, it is open source, which resonates with a majority of the software development community, according to Fausto de la Torre, head of technology for Thoughtworks. Additionally, it has the support from one of the top technology giants in the industry. Google announced support for the programming language at its Google I/O conference in 2017. But, even before Google’s announcement, many developers were already starting to switch their development efforts to Kotlin.
According to Chet Haase, chief advocate for Android at Google, Kotlin breaks a pattern that too many traditional programming languages have become accepted. “The more established something is, the slower it tends to move,” he said. “After a few years, [language providers] don’t want to completely change things and adopt new paradigms into the language that are going to force things onto developers that they are not ready for.” This was also a main concern for Google when thinking about adopting Kotlin. “We [didn’t] want to jolt Android developers and make them change everything by introducing some new concept,” Haase explained.
Kotlin takes a different approach because it is completely interoperable with Java, allowing Kotlin developers to take advantage of Java’s existing ecosystem of libraries and frameworks.
How it compares to other languages
That interoperability can be a tradeoff when it comes to Kotlin, though, Thoughtworks’ de la Torre explained. Because most developers adopting Kotlin are Java developers, they tend to write Kotlin in a Java style, but there are some Java behaviors, keywords and features that don’t translate well when using Kotlin. “Kotlin can use the entire ecosystem of Java. That is one of the strongest things it has, but to try to use it in the same way is challenging,” he said. “You cannot use it as straightforward as you think.”
Stephanie Cuthbertson,a director of product management for Google’s Android shared about half of the Android development community is using Kotlin. When you look at the other languages in the Android ecosystem, C++ and Java represent a certain state of the art at a given time. For instance, C+ represents data structures and algorithms, and Java represents an object-oriented language that introduced things like automatic memory management; but Kotlin represents a more modern way of working today, Cuthbertson explained. “What developers told us they love about Kotlin is all of its modern idioms,” she said. Some examples of these include: coroutines and nullability. Coroutines introduces a new way to write asynchronous and non-blocking code. Kotlin also enables the ability to declare something explicitly null and ensure developers don’t run into null reference exceptions that can cause quality issues later on.
Cuthbertson also believes the language is set up to evolve more quickly over other languages because instead of being committee driven, the Kotlin language is stewarded by the Kotlin Foundation and the language design itself is done by the lead language designer Breslav. Breslav has been running a community process where he takes in a lot of input from other developers, but he is the single person who looks after it. “What that means is the language is continuing to evolve rapidly in a way that has a coherence to it,” said Cuthbertson. “The Kotlin language is intentionally designed so we can evolve rapidly, but evolve in a way that protects the purity of the language while taking in community input in a really healthy way.”
Additionally, Android’s Haase explained the strength of Kotlin is the fact that it was designed and developed by the IDE company JetBrains. “The features of the language at its core as well as the new features are tightly integrated into the development environment that developers use. While other languages have IDEs that are very good at development with that particular language, the language itself is independent of those IDEs,” he explained. IntelliJ IDEA is the underlying platform of Google’s IDE Android Studio.
Thoughtworks’ de la Torres finds its team drawn to Kotlin because it increases developer productivity and provides a better developer experience than other languages. Kotlin has the ability to achieve the same things as other languages, but with less lines of code in a more modern way, he explained.
“Once you get the hang of writing Kotlin, you write less code. Because you have less code, that code is more maintainable. Because of things like nullability, you have higher quality code. And because of modern idioms, it is much more enjoyable,” said Cuthbertson.
de la Torres did add that the Kotlin community isn’t currently as strong as other languages. “While it continues to grow, it is still not very mature yet and there are some gaps still needed to be filled,” he said. De la Torres added he would like to see more work done with testing frameworks and continuous delivery. Google is currently working on investing and growing the community as well as providing training to help developers understand how Kotlin can be integrated into their code and solutions. “Not only do we think it is better for our developers, but we think it is also better for us,” explained Haase. Google is currently using Kotlin in its Android Jetpack and other libraries.
Beyond Android development
Right now, Kotlin is well known for its rise in Android app development, and while Google is still making strong investments in other languages, it is pushing for Kotlin. “If you are making a new project, we recommend you start in Kotlin. We are starting a Kotlin-first approach in the Android OS,” said Android’s Cuthbertson.
But Thoughtworks’ de la Torre sees the language demonstrating its value beyond mobile development.
Thoughtworks currently sees teams building microservices and deploying software into production with Ktor, a framework for building asynchronous servers and clients using Kotlin. MockK is another Kotlin solution used for mocks and testing Kotlin applications. “As a native library, it helps our teams to write clean and concise code on testing Kotlin applications instead of using the inconvenient wrappers of Mockito or PowerMock,” Thoughtworks wrote in its Technology Radar. In addition, Thoughtworks uses Detekt for static code analysis in Kotlin, and http4k for serving and consuming HTTP services in Kotlin.
The Kotlin team is also working to bring the language beyond mobile app development with Kotlin/Native, a solution for compiling Kotlin code to a variety of platforms without running a virtual machine. “Kotlin/Native is primarily designed to allow compilation for platforms where virtual machines are not desirable or possible, for example, embedded devices or iOS. It solves the situations when a developer needs to produce a self-contained program that does not require an additional runtime or virtual machine,” JetBrains wrote on its website. Kotlin/Native currently supports iOS, MacOS, Android, Windows, Linux and WebAssembly.
Google is also trying to move Kotlin beyond Android development with the adoption of Kotlin for cloud development.
In a recent Kotlin Consensus report conducted by JetBrains, the company found 39 percent of respondents use Kotlin as their primary language, 46 percent use Kotlin for server-side production code and 10 percent use it for data science. The report was based off of more than 4,000 responses from Kotlin users. “Today more than 2 million people use Kotlin on every kind of platform, for the development of all possible types of software. More than 250 contributors help drive development and the ecosystem forward. We are very happy with the dedication and hard work of our community who have contributed so much to the Kotlin learning materials and spreading Kotlin knowledge,” the Kotlin team wrote in a blog post.
Google’s five reasons for adopting Kotlin
Adopting a new programming language to an existing and established platform like Android could be startling for developers because it can create a disjointed environment between existing apps, libraries, code, the new language and new APIs.
“It is always a consideration of whether or not a platform should adopt another language, and the answer has always been no because of that jolt effect,” said Chet Haase, chief advocate for Android. “However when we floated the idea of Kotlin to developers, they were very [interested].”
According to Stephanie Cuthbertson, director of product management for Google’s Android, there were five main drivers that brought Google to announce its support in 2017.
- “It is a beautiful programming language,” said Cuthberthson. Because it is a modern programming language, it takes advantage of many new best practices developers are already familiar with.
- It is completely interoperable with Java, allowing developers to call back and forth between languages.
- Maturity. By the time Google decided to adopt Kotlin, it had already been around for five years and had reached 1.0 stability.
- IDE support. Kotlin is created by the creators of JetBrains’ IntelliJ IDEA, the underlying platform of Android Studio, so it provides enhanced support for both the IDE and language.
- Community. “We adopted Kotlin to Android because the community really wanted it,” said Cuthbertson. In fact, Cuthbertson explained there was an open letter to Android from the community asking the team to adopt it shortly before Google made its announcement.
“It is not just growing, people really love it,” said Cuthbertson. “It was this set of things… that caused us to tip the balance and say ‘it is really time to lean in.’”