DEV Community

Cover image for Should new Android developers learn Compose or XML?
Aldo Wachyudi
Aldo Wachyudi

Posted on

Should new Android developers learn Compose or XML?

In the next three months, I'll be volunteering to teach undergrad students Android development. So, I'm also faced with this question, should I teach a new developer Compose or XML?

In my opinion, aspiring Android developers should just start learning Compose. Here are my four reasons why:

1. Production-ready

Compose is ready for production. Twitter, Play Store, and Airbnb are just a few companies that already using Compose. It has been more than one year since Compose reached version 1.0.

What do I mean by production ready?

  • No major bugs or unnecessary troubleshooting.
  • The APIs are stable, consistent, and intuitive.
  • There is no performance issue, your User Interface (UI) will render smoothly.

When I'm coming back to Android development after working as a backend engineer for a year, I'm curious whether I can build a complex UI with Compose. As a proof of concept, I've made a clone of Astro, a quick commerce app that I believe has typical requirements of the real app (layered UI, custom behavior, multiple UI sections, etc.).

So, you don't need to worry that you will encounter too many issues when learning Compose. You can publish a real app with Compose.

2. Simplicity

This is an example of how you write UI using XML.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hi, my name is Aldo" />

    <ImageView
        android:id="@+id/ivProfile"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

    <TextView
        android:id="@+id/tvRole"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="I'm an Android developer πŸ€–" 
        />

</LinearLayout>
Enter fullscreen mode Exit fullscreen mode

And this is how you write UI using Compose.

Column {
    Text("Hi, my name is $name", style = TextStyle(
        fontWeight = FontWeight.Bold))
    AsyncImage(model = "https://example.com/img/user.png")
    Text("I'm an Android developer πŸ€–")
}
Enter fullscreen mode Exit fullscreen mode

Even from this simple use case, you can see that Compose uses fewer lines of code.

The simpler the code, the easier it is to learn or to teach it.

You don't need to learn:

  • XML (just use Kotlin)
  • Binding XML to a Kotlin class
  • Improving performance by flattening your View hierarchies using ConstraintLayout

This means you've got more time to learn other Android topics, like ViewModel, testing, Coroutines, and Jetpack libraries.

3. Familiarity

If you've learned declarative UI from other platforms, you will feel right at home.

Take a look at these code snippets that build the same UI for iOS (SwiftUI) and cross-platform (Flutter).

VStack {
    Text("Hi, my name is \(name)!")
        .fontWeight(.bold)
    AsyncImage(url: URL(string: "https://example.com/img/user.png"))
    Text("I'm an iOS developer 🍏")
}
Enter fullscreen mode Exit fullscreen mode
Column(
    children: const<Widget>[
        Text('Hi, my name is $name', style: TextStyle(
            fontSize: FontWeight.bold)),
        Image.network('https://example.com/img/user.png')
        Text('I\'m a Flutter developer ⬅️')
    ]
)
Enter fullscreen mode Exit fullscreen mode

It looks somewhat similar, isn't it?

Chances are, a new Android developer is not going to pursue a career as a full-time Android developer. They might be exploring Flutter, iOS, backend, or not even pursuing a career as a developer.

By using Compose, you've learned a concept that can be applied to other platforms.

4. Support

Learning anything new can be difficult at first, no matter how good a library is. When you're stuck, Compose has many resources to help you, from official Android documentation to a plethora of community articles. To mention some:

You don't need to worry about integration with popular libraries as well. Popular libraries like Jetpack Components (ViewModel, Navigation, Hilt, etc.), Glide, or Koin is compatible with your Compose code.

Compose is still actively supported by Google, so even if you find a bug or a feature request, you can expect it's addressed in the next version.

Summary

In conclusion, Compose is a safe choice for a developer who's just getting started with Android development. While XML is still dominant in the legacy project, Compose is the modern toolkit for building native Android UI. Go ahead and use Compose in your first app!

Notes

  • I'll be teaching Pemograman Mobile course at Universitas Musamus Merauke (UNMUS) as part of praktisimengajar.id government program. Thank you for giving me this opportunity!

  • To be fair, XML is declarative UI too, a verbose one compared to Kotlin. But in XML, you still need to write imperative code for many tasks.

  • Cover photo is taken by weston m

Top comments (6)

Collapse
 
raihanadf profile image
Raihan

mantaps

Collapse
 
umardev500 profile image
Umar

I don't like compose because it uses Skia which big problem is janky issue

Collapse
 
anshulnegi007 profile image
anshul negi

amazing blog Aldo!... πŸ™Œ πŸ™Œ

bookmarked

Collapse
 
aldok profile image
Aldo Wachyudi

Thank you! I'm glad you enjoyed it. Your support means a lot. πŸ™Œ

Collapse
 
souravkarjole profile image
souravkarjole

Okay Composs is great choice, But is it still worth learning XML in 2024 ? If yes than how much time to invest in XML?

Collapse
 
aldok profile image
Aldo Wachyudi

But is it still worth learning XML in 2024?

Yes, there are still many uses for XML, especially in older projects.

If yes, then how much time should be invested in learning XML?

I’d say don’t invest too much time in it. With the increasing popularity of React Native, SwiftUI, and Flutter in 2024, learning Compose will provide you with more transferable skills across these platforms.