Software

Well, this makes scents: Kotlin code quality smells better than Java

Google-backed language seeps into Android apps, improves programming craftmanship

By Thomas Claburn in San Francisco

30 SHARE

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.

Kotlin is an open source statically typed programing language that targets the JVM, Android, JavaScript (transpiling to ES5.1) and native platforms (via LLVM). JetBrains, the company that created it, contends Kotlin is more concise and more type-safe than Java. It estimates that apps written in Kotlin require about 40 per cent less code than they would with Java. With fewer lines of code, in theory, one can expect fewer bugs.

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.

"Smells" is a more visceral alternative to "anti-patterns," a term of art used to refer to bad coding patterns. In Java, The Blob (a.k.a God Objects) represents a commonly cited anti-pattern.

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 devs

READ 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." ®

Sign up to our NewsletterGet IT in your inbox daily

30 Comments

More from The Register

Red Hat sticks its storage software cap on Supermicro hardware

Software-defined storage meets single SKU-ery

The quickening: Qumulo speed with software boost for new kit

I was born in 1518... we mean.. machine learning-driven caching speedup

Buggy software could lock a Jeep's cruise control

How's that 'self-driving' vision coming along, again?

Facebook can't root out fake news and hate talk, but – oh look – it has software to catch bugs

Plans to open source app, server-side code-fixing tool

Killer performance numbers on software and flash drives, StorONE ...

Would be good to see some independent tests, though

BlackBerry continues its gentle slide even as software sales embiggen

Strong showing for that and services in Q1 '19 results

Yarrrr, the Business Software Alliance reckons piracy be down, me hearties

Report: dodgy software still accounts for beeeellions of lost cash and malware aplenty

Cisco kicks shrivelling video software unit back to Dr Martens owner

Word on the street: it's getting far less than $5 beeellion it paid

Want ScaleIO virtual SAN software? You'll need to buy Dell servers

Integral part of VxRack FLEX hyperconverged kit henceforth