Google's firsthand experience of what to consider when switching from Java to Kotlin.
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.
"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.
- Kotlin and Terraform ecosystems gain ground in the enterprise
- Want to learn the fastest-growing programming languages of 2019? Check out these two unstoppable newcomers
- How to learn Kotlin: A resources guide for developers
- Why Kotlin is exploding in popularity among young developers
- Microsoft's GitHub: 'Kotlin for Android now fastest-growing programming language' (ZDNet)
- Which programming languages pay best, most popular? Developers' top choices (ZDNet)