Facebook’s parent company Meta revealed that the language it uses to develop Android applications has migrated from Java to Kotlin, a younger programming language that also relies on the Java Virtual Machine (JVM).
Created by software tool maker JetBrains, Kotlin debuted in 2011 and released version 1.0 in 2016. The following year, Kotlin was adopted by Google as the first (supported) language for Android development and placed under the governance of its own foundation, funded by JetBrains and Google.
Join us on Telegram
Before that, most Android apps were written in Java. In May 2019, at its developer conference, Google started encouraging Android developers to favor Kotlin over Java. At the end of that year, Google said that 60 percent of the top 1,000 Android apps contained Kotlin code.
Google recommends Kotlin because it is more concise, safer, supports structured concurrency, makes asynchronous code easier, and is interoperable with Java.
But it may also have something to do with Java custodian Oracle, which spent more than a decade filing (and ultimately failed) infringement claims against Google over the Java API used in Android.
Meta also appears to be interested in Kotlin, with Facebook software engineer Omer Strulovich saying they are already replacing Java code with Kotlin in several of its popular Android apps, including Facebook, Instagram, Messenger, Portal, and Quest.
” Kotlin is widely regarded as a better language than Java, and is rated higher than Java in the annual Stack Overflow developer survey, ” Strulovich said, noting that Kotlin has become a popular language for Android development, ” Therefore, it makes sense for us to move Meta’s Android development to Kotlin.”
But aside from its popularity in the Android ecosystem, Strulovich admits that in the wider market its popularity is still far behind that of Java, which is the second or third most popular language in the world.
The advantages of Kotlin over Java include built-in nullability handling, support for inline functions and lambda expressions, shorter code, and the ability to define a DSL (Domain-specific language).
The downside is that you need to face mixed codebases for a long time, which is harder to maintain, and Kotlin has been around for a shorter time than Java and has a less mature set of tools.
“Today, our Android apps for Facebook, Messenger, and Instagram all have over 1 million lines of Kotlin code, and conversion rates are increasing,” Strulovich said. “Our Android codebase has over 10 million lines of Kotlin code in total.”
Strulovich didn’t say when Meta started the transition, or what percentage of its Android app code was converted. “On average, we’ve seen an 11% reduction in lines of code with this migration,” Strulovich said. “And there’s no performance regression, so at least the converted applications have maintained their original performance.”
Strulovich said Meta’s migration is ongoing and accelerating, but he also said: “Kotlin still lacks some of the tools and optimizations we’re used to in working with Java. But we’re working to close those gaps. As we make progress, And as these tools and libraries mature, we will also work to put them back into the community.”