Does Kotlin popularity increase code quality better than Java?

Google announced on I/O 2017 that Android has added support for the Kotlin programming language. Today, in all open source Android applications, we can see that 12% is developed by Kotlin. At the end of 2017, Google said that Kotlin has penetrated more than 17% of Android apps developed using IDE, Android Studio 3.0.

Kotlin is a statically typed programming language that runs on a Java virtual machine and was open sourced in 2012 with an Apache 2.0 license. It is not compatible with Java’s syntax, but is designed to be interoperable with Java code, reuse existing Java class libraries, and is considered to require less code, while less code usually means fewer bugs. Google’s then released Android Studio 3.0 added Kotlin support.

A year later, computer scientists Bruno Gois Mateus and Matias Martinez of Valenciennes University in France published a paper entitled “An Empirical Study on Quality of Android Applications written in Kotlin language” to study the quality of Android applications written in Kotlin.

Original paper:

In their paper, they describe how to collect 925 applications from the open source app store F-Droid, and how to measure the performance of Kotlin code in each application, and analyze the code “smells” as a measure of code quality.

Note: “Smells” is another term for “anti-patterns”, a term used to refer to poor coding patterns. In Java, The Blob (aka God Objects) represents a commonly cited anti-pattern.

By analyzing the 925 applications, it was found that at least one version of 109 applications was written in the Kotlin language, and 35% of the applications only used the Kotlin language. In applications that include Java code and Kotlin code, the Kotlin code ratio increases and the Java code decreases in more recent versions.

Then analyze the code quality:

Object-oriented (OO) anti-patterns include Blob Class (BLOB), Swiss Army Knife (SAK), Long Method (LM), and Complex Class (CC).

Android anti-mode includes Heavy Broadcast Receiver (HBR), Heavy AsyncTask (HAS), Heavy Service Start (HSS), Initial OnDraw (Init OnDraw, IOD), no memory resolution No Low Memory Resolver (NLMR) and UI Overdraw (UIO).

In object-oriented anti-patterns, LM, CC, and BLOB appear in at least 92% of Kotlin and Java applications, with OO “odor” being more common in Kotlin applications. But the researchers found that in this Android “odor”, Java is more susceptible to three “odors” than Kotlin.

affected applications by smell

Researchers have also mentioned in the paper that the adoption of Kotlin has improved the quality of at least 50% of Android apps. Therefore, Kotlin’s code is considered to be of higher quality.

In addition, the two researchers also compared the Objective-C application and the Swift application and found that the Android application’s outliers are higher than the iOS application.