As of 2021, Kotlin is now a generally available language across all of Google. The company first announced in 2019 that it was taking a Kotlin-first approach in Android, but since then it has expanded its support and implemented Kotlin in more than 60 applications such as Google Home, Drive, Maps, Pay, Sheets, and Docs.
“What we have really seen is that our developers love it, and we’ve seen a ton of growth just in terms of usage both outside and inside Google,” said Karen Ng, product lead for Kotlin and Android development tools.
Ng explained the adoption happened organically within the company. Before Google decided to adopt it, the Android community wrote an open letter to the company about Kotlin and its benefits.
After adopting it, Google found it was just easier, safer and more reliable to work with than other languages. For instance, it’s fully interoperable with Java, making it easier for developers and Google to adopt it without having to rewrite a bunch of code, according to Ng.
RELATED CONTENT: The rise of Kotlin
Kotlin also provides safer code by being able to take nullable and non-nullable information into the type system and help developers avoid whole crashes, Ng explained. Google Home was able to reduce crashes by more than 30% with the help of Kotlin.
“The Google Home team decided to incorporate Kotlin into their codebase to make programming more productive and to enable the usage of modern language features like var/val, smart casts, coroutines, and more,” the company revealed in a case study. “Because Kotlin can make nullability a part of the language, tricky situations can be avoided, like when inconsistent usage of nullability annotations in Java might lead to a missed bug. Since the team started migrating to developing new features with Kotlin, they saw a 33% decrease in NullPointerExceptions. Since this is the most common crash type on Google Play Console, reducing them led to a dramatically improved user experience.”
Other features like coroutines were especially important for Google to be able to help mobile apps handle asynchronous data.
Ng also found developers are able to do more with less code, “which makes it a lot more maintainable, easier to read, and you get improved productivity.”
Swiggy, the online food ordering app company, wrote 74% of their app in Kotlin and saw a 50% reduction in crashes as well as huge improvements in app rollout times, Ng revealed.
“When we survey developers in our benchmark survey on language satisfaction or productivity, we find that developers find themselves much more productive in Kotlin. It’s the conciseness of code, the type safety extension functions, and coroutines that [enable developers] to ship apps faster with Kotlin,” said Ng.
In addition to it becoming a general availability language, Google launched a new curriculum to help more developers get started with Kotlin. “The reason why this is important is because we see so many different career opportunities for Android developers in our ecosystem, we want more people to be able to take advantage of this regardless of what background they come from, even people with no programming experience,” said Katherine Kuan, developer advocate for Android.
The company has invested in learning materials for different backgrounds and learning systems. There are course materials available for developers who want to learn online at their own pace; developers who want to learn in a peer group; and developers who prefer more structured learning.
Kuan recommended those learning Kotlin as a first language take advantage of the Kotlin Playground, which is “in the browser so without even needing to install an IDE, you can start writing a simple Kotlin program and playing with the syntax. That gives people an easy win upfront.”
Google is also trying to help developers who are coming from Java. Ng explained that Java developers tend to try the same flow or idioms as they would in Java that aren’t necessarily efficient in Kotlin. “Some of our content and training has now started thinking about Kotlin idioms, how you might think of writing something a little bit differently,” she explained.
“With the digital world, there is such a need for growing skill sets and time is more precious, so a language like Kotlin helping you become more productive just becomes that much more valuable,” Ng added.
Going forward, Google plans to continue to grow and improve the language inside of Google. The company recently announced the beta version of Jetpack Compose, its UI toolkit, which is built on Kotlin.
“Built entirely in Kotlin, Compose takes advantage of its great language features to offer powerful, succinct, intuitive APIs. Coroutines for example enable us to write much simpler async APIs such as describing gestures, animation or scrolling. This makes it easier to write code that combines async events, like a gesture which hands off to an animation, all with cancellation and clean-up provided by structured concurrency,” Anna-Chiara Bellini, Android product manager, and Nick Butcher from Android developer relations, wrote in a post.