Should Android devs switch from Java to Kotlin? Here's Google's advice on swapping programming languages

Google's firsthand experience of what to consider when switching from Java to Kotlin.

The best programming languages to learn in 2019: Top coding skills that pay you the most These are the languages that are in the highest demand and offer the highest salaries.

Google has weighed in on whether Android developers should switch from building apps with Java to using Kotlin.

Google's tech lead for Android Studio Jeffrey van Gogh said the question had been raised by the announcement that Android development would become 'Kotlin-first'.

But what does 'Kotlin-first' Android development mean? Speaking at the Google I/O conference this week, van Gogh spelled out the consequences for both Java and Kotlin.

"Of course we're going to keep supporting the Java programming language in many aspects," he said, showing the table below.

kotlinjavaandroid.jpg
Image: Google

"But if you look at some other efforts, like our online training samples, we'll first do Kotlin and then the Java programming language will be 'best effort'. Then, of course, there are some features, like the multi-platform projects and [the UI toolkit] Jetpack Compose, that are only going to be offered in Kotlin."

SEE: Tips for building a successful career as a software engineer (free PDF) (TechRepublic)

Google is well placed to answer whether Android developers should switch from Java to Kotlin, having started using Kotlin in a range of its own products, including Google Drive, Google Home, nest, and Android SystemUI.

"Please don't take 'Kotlin-first' as I need to go take all my Java code and rewrite it in Kotlin. That's not what we want you to do," he said, adding that Google itself hasn't taken that approach with existing software.

"Look at Android Studio, that is many, many hundreds of thousands lines of code. Right now, we're about 10 percent Kotlin of the Android Studio-specific code.

"What we do is we only take new functionality and write it in Kotlin. It is possible because Kotlin has great interoperability with Java. You can write a single class in Kotlin and keep the rest in Java, or have 99% of your code in Kotlin and have only some of the leftovers in Java."

Complicating factors, such as the stage of the app development, also need to be considered, he added, saying that implementing new functionality in Kotlin obviously made more sense closer to the beginning of a project.

Another question for teams, he said, is how much enthusiasm there is for Kotlin internally?

"It depends on your team as well. Are they interested in Kotlin? Do they feel secure taking this on?" he said.

There are also downsides to weigh up, with van Gogh saying it will take some time before developers are familiar with the conventional way of writing Kotlin, known as writing idiomatic code.

"Kotlin brings great features, a lot more productivity and satisfaction, but you have to think about the learning curve, it takes time for people to learn to write idiomatic Kotlin," he said.

"We see that most people who start writing Koltin the first week, they're really writing Java in Kotlin, and it takes them three-to-six months to to really start writing idiomatic Kotlin."

The software build process can also take longer, he said, due to the Kotlin compiler being slower than those typically used with Java, although he said Google is "working hard" on making the compiler faster.

When using Kotlin, the generated APK, the software package used to install the app on Android devices, is also relatively large too, he added.

Google has "a whole bunch of ongoing Kotlin work" for Android, he said, including Jetpack Compose, new Kotlin Extension (KTX) APIs for Jetpack, and is building on work to make the compiler faster that got underway in the latest 1.3.30 Kotlin release, as well as improving tooling, documentation and code samples.

If you're interested in learning more about Kotlin, check out TechRepublic's guide to free resources that are available.

Read more

By Nick Heath

Nick Heath is chief reporter for TechRepublic. He writes about the technology that IT decision makers need to know about, and the latest happenings in the European tech scene.