Google pushes Kotlin again: 80% less code than Java

Last week, Google just launched a free Kotlin and Android online course that teaches developers to build Android apps using Kotlin. Soon, the Google Home team came out and demonstrated the benefits of Kotlin’s development through their own experience.

The Google Home app can be used to connect and manage a wide range of smart home devices. Like many apps affected by Google’s “Kotlin-first” initiative, Google Home has chosen to include Kotlin in its code base. As of June this year, about 30% of the code in the app was written in Kotlin, and future new features were encouraged to be developed with Kotlin.

The Google Home team mentioned that the Jetpack open source UI kit, also promoted by Google, combines the simplicity and ease of use of the Reactive programming model with the Kotlin programming language to simplify UI development.

Although only one-third of the code has now migrated to Kotlin, its efficient and concise features have made the Google Home team feel more impressive. They use the use of data classes and Parcelize plug-ins as examples: a class of 126 lines of handwritten code in Java can be represented in Kotlin with only 23 lines – an 80% reduction in the amount of code. In addition, some function methods in Kotlin simplify many nested loops and filtering checks.

Kotlin’s emptyness, on the other hand, was praised. Still compared to Java, the Google Home team notes that “inconsistent usage of empty comments in Java can result in missing bugs.” Since Adopting Kotlin, Google Home’s NullPointerExceptions have decreased by 33%, the most common type of crashes on the Google Play console, and the resulting reduction in the number of crashes may significantly improve the user experience.

Google pushes Kotlin again: 80% less code than Java

The Kotlin programming language was introduced by JetBrains in 2011, open source in 2012, became the official Android development language in 2017, and became the official preferred language for Android development in 2019.

From initial support for Kotlin to “Kotlin-first”, Google has been supporting it in many ways, launching Aftin free online courses and courses using Kotlin to build Android apps, and constantly improving the ecosystem, such as the opening of gRPC-Kotlin/JVM in April this year to make it easier for developers to use gRPC in Kotlin projects.

With Google’s push, Kotlin’s attention has skyrocketed, and the latest JVM Eco report shows that Kotlin has become the second most popular JVM language. In an interview with Open Source China, Shen Zhe, an Android development expert, noted that some domestic companies are also using Kotlin to develop Android projects, and that “more and more developers are choosing Kotlin as the preferred development language for native apps.”

As a JVM language, a compatible language that is even considered to replace Java, Kotlin’s appearance is often accompanied by comparisons with Java. Google has even launched an official guide to migrating from Java to Kotlin. Some Android developers are still hesitating about whether to move to Kotlin, and some have moved from Java to Kotlin and back to Java. In a survey published by The Dice’s website a year ago, 85 percent of respondents almost sided with the choice to still use Java to build Android applications.

But in the real view of Google engineers, there is no need to draw a complete line between the two. Jeffrey van Gogh, head of technology at Android Studio, has said that Java and Kotlin are highly interoperable, so they can all coexist in the same project. Many of Google’s own apps, such as Google Home, now use this converged approach, and Kotlin is more used to write new features.

So, back to the question of “Kotlin or Java”, which may have bored Android developers, the conclusion clearly doesn’t exist, and the key is to choose the best way.