|Can a Language Make You a Better Programmer? Kotlin & Android|
|Written by Mike James|
|Wednesday, 08 August 2018|
When Google introduced Kotlin as a fully supported language for Android development, a lot of programmers raised a cheer. The question is why? Can a language make a difference?
Kotlin is a Java-like language that compiles to the JVM, among other targets. It aims to be a better Java in the sense that wherever Java has a lot of code to get a job done, Kotlin tries to simplify. It does this not by simple syntax tricks, but by trying to find new abstractions that let the programmer do what they are trying to do without as many hoop to jump through. Of course, this in turn does lead to a simpler syntax.
As a Kotlin user I can vouch for the fact that the language does seem to work with you, rather than get in the way.
But does Kotlin make me a better programmer?
Now two researchers at the University of Valenciennes have attempted to answer the question. First they looked at a repository of open source Android apps and discovered that just short of 12% were using some Kotlin. This is in line with Google's own estimate of around 17%. What is more surprising is that they found that, of the 12%, around 35% use nothing but Kotlin. Putting this another way, 4% of the total use nothing but Kotlin.
Distribution of Kotlin code in apps that use it
Given that Kotlin was only introduced in the middle of 2017, this is a fairly high proportion. It would have been interesting to know if these are completely new apps or have 4% of the apps been re-implemented in Kotlin - a big leap of faith.
Looking at the mixed Kotlin/Java apps' evolution over time, there was clear reduction in Java code and an increase in Kotlin. This suggests that once tried Kotlin isn't given up. It would be interesting to know if there are any specific tasks where Kotlin is abandoned because Java is actually more suited. I can't think of any.
OK, so Kotlin is gaining ground and once used isn't given up, but does it make the apps any better?
This is a much more difficult question to answer because we haven't really got a clear idea of what to use to measure "better". In this case a standard analysis of code "smells" was used.
It has to be admitted that in this case the results aren't as clear. Regarding the pure object-oriented smells Kotlin did slightly worse than Java in terms of just having an instance of the smell on three of the four tests: Blob Class (BLOB), Complex Class (CC) and Long Method (LM). Does this suggest that Kotlin conversions are having problems with refactoring the existing Java code? For Android specific code smells, there is no significant difference except in one smell - No Low Memory Resolver (NLMR), i.e. no onLowMemory overrride. Why Kotlin should make this easier is not at all obvious.
Kotlin apps show evidence of the code smells slightly more often than the Java apps, but when you look at how many entities are affected by them you find that Java apps are worse.
More interestingly, the quality scores of the apps that adopted Kotlin improved over time from the final Java-only version. That is, Kotlin doesn't doesn't eliminate the smells from the code base but it does reduce their rate of occurrence. You can see a sample chart for one app below:
Of course, there are example of apps that got worse when Kotlin was introduced, but overall they did seem to improve.
"We concluded our study analyzing the impact of Kotlin on the quality of an Android application. 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% of the applications."
So - Kotlin good; Java bad!
Not quite. There are a lot of other considerations and code smell isn't a direct measure of code quality. The researchers plan to continue looking at the impact of Kotlin on Android development.
My own experience is that Kotlin does make things easier and being easier you tend to go the extra mile simply because you can, i.e. you have the time and energy left over to do the job better. There is also something about seeing the more compact code and being able to notice when it could be improved. If only Android Studio was as usable as Kotlin. Currently I would rate Android Studio as my biggest time waster.
or email your comment to: email@example.com
|Last Updated ( Wednesday, 08 August 2018 )|