Well, this makes scents: Kotlin code quality smells better than Java
Google-backed language seeps into Android apps, improves programming craftmanship
Kotlin, which Google blessed last year as an alternative to Java for programming Android apps, has already made its way into almost 12 per cent of open source Android apps, and in so doing has elevated their code quality.
So we're told by computer scientists Bruno Gois Mateus and Matias Martinez, affiliated with University of Valenciennes in France, who observed that Google at the end of 2017 said Kotlin had infiltrated more than 17 per cent of Android apps developed with its IDE, Android Studio 3.0.
In a paper distributed through pre-print service ArXiv, "An Empirical Study on Quality of Android Applications written in Kotlin language," Mateus and Martinez describe how they gathered 925 apps from the open source F-Droid repository, measured the amount of Kotlin code in each, and analyzed the code for "smells" as an indicator of code quality.
The code boffins found that 109 out of 925 applications in their F-Droid dataset had at least one version between 2017 and 2018 written using Kotlin.
Among the most recent versions of each Kotlin-positive app – they looked at multiple versions when available – 35 per cent were written exclusively with the language. And for about 68 per cent of the Kotlin apps, the amount of Kotlin code increased in subsequent versions while the amount of Java code dwindled.
For their code quality sniff test, the researchers relied on Paprika, a toolkit to "detect some code smells in analysed Android applications."
Their conclusion: Java stinks (or more charitably, Kotlin smells like roses).
And yet Java persists
Using Paprika, they tested for 10 distinct smells, 4 related to object-oriented (OO) code and 6 related to Android.
The object-oriented anti-patterns included: Blob Class (BLOB), Swiss Army Knife (SAK), Long Method (LM), and Complex Class (CC). And the Android anti-patterns included: Heavy Broadcast Receiver (HBR), Heavy AsyncTask (HAS), Heavy Service Start (HSS), Init OnDraw (IOD), No Low Memory Resolver (NLMR), and UI Overdraw (UIO).
Kotlin's killin' Java among Android devsREAD MORE
Among the OO patterns, 3 out of 4 – LM, CC and BLOB – showed up in at least 92 per cent of both Kotlin and Java apps, with OO smells being more common in Kotlin apps.
But the computer scientists found Java apps overall had more entities affected by 4 of the 10 scents than Kotlin, where only 1 in 10 apps induced gagging.
"Regarding the immediate impact of introducing Kotlin on Android applications, i.e., the first version that has Kotlin code, we found that the adoption of Kotlin produces a rise of the quality from, at least, 50 per cent of the applications," the paper declares.
Incidentally, a separate group of researchers – Sarra Habchi, Geoffrey Hecht, Romain Rouvoy, and Naouel Moha – last year conducted a similar sniff test spanning both iOS and Android apps.
Comparing Objective-C apps and Swift apps, they found that iOS apps have roughly the same proportion of bad smells regardless of programming language, but stink less than Android apps. They conclude, "while the results clearly indicate that the Android apps have more outliers than the iOS ones, this does not necessarily mean that Android apps are globally worst in terms of quality." ®