Programming languages: Why is Meta porting its Android apps from Java to Kotlin

Programming languages: Why is Meta porting its Android apps from Java to Kotlin

Photo: Getty Images / Nitat Termmee

Engineers at Meta, the parent company of Facebook, detailed their multi-year effort to convert the code bases of many Android applications from the Java programming language to Kotlin.

This is a big job for a company with thousands of developers and many big Android apps, including Facebook, Instagram, Messenger, Portal and its Quest VR headset.

Moving away from Java, which we currently use for Android development, and Kotlin’s job is not a trivial onenotes Omar Strolovich, a software engineer at Facebook.

also: Salary freeze and return to the office? Not for software developers

The transition to Kotlin is underway, as the Meta app repositories for Android already consist of 10 million lines of Kotlin code.

“Today, our Android apps for Facebook, Messenger, and Instagram contain more than 1 million lines of Kotlin code, and the conversion rate is increasing. In total, our Android code contains more than 10 million lines of Kotlin code,” Strolovich said.

Java is one of the top three programming languages, thanks to its dominance in enterprise applications, while Kotlin is less well known but still Top 20 Programming Languages. Meta’s shift away from Java to Kotlin for Android application development is a milestone, given the scale of Meta and the size of its applications.

But, despite the benefits of Kotlin that catalyzed the Meta switch, Strulovich identifies several important flaws that make this move risky, at least for larger applications.

First, the huge gap in popularity between Java and Kotlin leaves the latter with fewer tools, and these tools, which must take into account the interoperability of Kotlin-Java, are complex. Although the languages ​​are 100% interoperable, Meta has found that it cannot remove all Java.

“Kotlin is a popular language, but compared to Java, the popularity gap is obvious. Java is the second or third most popular language in the world (depending on how one measures it). This means fewer tools are available. Worse, Kotlin tools need Compute the interoperability of Kotlin and Java, which complicates its implementation,” notes Strolovich.

But the biggest Meta concern is slower build times in Kotlin vs. Java.

“We knew from the start that Kotlin build times would be longer than those of Java. The language and its ecosystem are more complex, and Java had a couple of decades of head start improving its compiler. Because we have many large applications, build times can negatively impact our developers’ experience” .

On this last point, Strolovich refers to the compilation of times after HTTP Client Project, OkHttp, switched from Java to Kotlin in 2019. OkHttp is small, with only 24,000 lines of Kotlin. Compile time in Java was 2.4 seconds compared to 10.2 seconds in Kotlin.

Meta engineers decided to convert almost all of their code to Kotlin instead of writing new code with Kotlin and leave most of the existing code in Java (the second method is how Linux kernel and Android Open Source Project work) Insert rust into their code).

A potential good news for Kotlin adoption elsewhere is that Meta has released several in-house Kotlin conversion tools on GitHub that others may be able to use directly, or at least can inspire others to find ways to automate conversion.

as such Engineers Facebook details In the past year, while Kotlin adoption can be smooth, it has been difficult at scale. Facebook uses its own Buck build system versus the IntelliJ / Android Studio IDE, which uses Gradle.

Strulovich identifies several Kotlin open source tools that Meta has contributed to, such as the “Pygments” library it uses to “make the experience on par with Java”. Meta has also built Ktfmt, a plugin for IntelliJ and Android Studio that provides a “deterministic Kotlin formatter based on the google-java format code and philosophy.”

also: Small businesses need more help with technology. Here are five ways to get it

So far, says Strolovich, Meta has seen an average of 11% decline in the size of its code base. The Google Home team reported a 33% decrease in the size of the application database on a new migration Kotlin features development.

“We’ve seen much higher numbers circulating online, but we suspect these numbers are derived from specific examples,” Strolovich said. “We’re still happy with that number, because the lines removed are usually standard code, which is less implicit than its shorter Kotlin counterpart.”

Kotlin was first developed by JetBrains, maker of developer tools or IDEs like IntelliJ. Google has been using Kotlin for Android apps since 2017, and the pair have jointly supported the Kotlin language through the Kotlin Foundation since 2018.

In 2019, the Android team at Google adopted a “Kotlin-first” approach. Google has more than 70 Android apps built at least in part with Kotlin, including Maps, Home, Play, Drive, and Messages. Google says that, compared to Java, Kotlin is more efficient, produces more secure code and a smaller codebase, and is 100% interoperable with Java – making switching from Java codebases easier by allowing it to coexist.

#Programming #languages #Meta #porting #Android #apps #Java #Kotlin

Leave a Comment

Your email address will not be published. Required fields are marked *