days
0
-38
0
hours
-1
-7
minutes
0
-1
seconds
-2
-1
search
How do you say "boilerplate code" in Spanish?

Duolingo migrates from Java to Kotlin, reducing line count 30%

Sarah Schlothauer
kotlin
© Shutterstock / Primakov

Duolingo has joined the list of companies switching their Android application code from Java to Kotlin. Duolingo’s developers found that by changing the code base to Kotlin, they reduced the line count by 30% on average, and up to 90% in some cases.

Many of us are diving into quarantine hobbies. Some of us are working on rainy day open source projects, knitting, gardening, and learning a new language. Duolingo, one of the most well-known language learning tools, has made a change of their own. They have migrated their Android app from Java to 100% Kotlin.

Duolingo isn’t alone in this move; they join companies such as Pinterest and Basecamp. Migrating from Java to Kotlin is becoming increasingly more common since Kotlin became the first-class language for Android development. It helps reduce the amount of boilerplate code while maintaining code readability and all of the positives of Java and JVM libraries.

SEE ALSO: COVID-19: Transparency becomes essential when working all-remote (Part 3)

Kotlin on the move

According to the Android developer blog, “Kotlin’s modern language features allow you to focus on expressing your ideas and write less boilerplate code. Less code written also means less code to test and maintain.”

According to The RedMonk Programming Language Rankings for January 2020, Kotlin is rising up the charts quickly. Data from GitHub and Stack Overflow suggests that it is now the 19th most commonly used programming language, moving up from #50 three years ago.

While traditionally, older languages have more of a mainstay in the enterprise, with newer languages delegated to hobbyists, Kotlin devs frequently use it professionally. According to the JetBrains state of Kotlin 2019, 71% of Kotlin devs use it at work and more than a third are migrating their existing codebase to Kotlin.

The key advantages Kotlin has over Java, as written by Juned Ghanchi are its data classes, null safety, compact syntax, single type system, extension functions, and immutability.

According to Snyk, it is now the second most popular JVM language, overtaking Scala and Clojure. Java is, of course, still top dog and will not be dethroned any tie soon. Nearly 90% of JVM users use Java as their main language.

Migration tips

Duolingo’s developers found that by changing the code base to Kotlin, they reduced the line count by 30% on average, and up to 90% in some cases.

The developer team used an autoconverter, which took care of a majority of the legwork. They recommend the following tooling for the big migration:

We lint all Kotlin code with detekt, IntelliJ inspections, Android Lint, and our own regex-based linter, Splinter.

For automatic code formatting, we run ktlint as part of a common pre-commit hook shared across all repos in the company. (The other main contender was the IntelliJ formatter, which we found to be slower and a bit more finicky to run in Docker.)

Once we got down to roughly 10% Java, we removed PMD, SpotBugs, and most inspections from our CI pipeline. Continuing to run these Java-specific tools would’ve slowed down our development speed while no longer offering much value.

SEE ALSO: Scratch claws its way up into top 20 programming languages

Java or Kotlin?

There are still some Java features that Kotlin does not support, however. So during migration, you may have to find a few workarounds. Besides that, there are few downsides to replacing Java with Kotlin code. A blog post on hackr.io by Vijay Singh goes over some of the differences.

Singh writes:

For general-purpose programming, Java gains the upper hand. On the flip side, more and more developers and organizations are adopting Kotlin for rapidly developing Android applications.

Do you plan to migrate? Or is Java still your number one?

Keep up with Kotlin news and the latest releases. And don’t forget your Duolingo lessons. Or else.

Author
Sarah Schlothauer

Sarah Schlothauer

All Posts by Sarah Schlothauer

Sarah Schlothauer is an assistant editor for JAXenter.com. She received her Bachelor's degree from Monmouth University and is currently enrolled at Goethe University in Frankfurt, Germany where she is working on her Masters. She lives in Frankfurt with her husband and cat. She is also the editor for Conditio Humana, an online magazine about ethics, AI, and technology.

Leave a Reply

avatar
400