Each year new technologies are emerging to make a developer’s life harder easier. Declarative UI has become one of the most remarkable trends of recent years as it:
- dramatically improves developer productivity
- reduces the development cost
- makes it easier to target multiple platforms and devices with the same code
However, it took a while for Google to build its own declarative UI framework before they finally released Jetpack Compose for native Android apps.
How Jetpack Compose is different from traditional UI Development
Starting from Java Swing and Win32 a vast majority of UI has been written in an imperative style. This also applies to both Android and iOS UI development.
Developers used to construct a full-functioned UI by manually describing how elements react to changes and update them later using setters when a state changes.
However, React, Flutter, SwiftUI, and Jetpack Compose took a different approach. With these frameworks, you tell what the UI should present instead of how elements should be constructed. The how part is left to the framework and the whole approach is called declarative UI.
Declarative UI is an industrial trend across web and mobile
Imperative UI was in place for a long time. It’s common, it’s robust, but it fails dramatically for large and complex reactive applications. Declarative UI showed great community adoption and development performance with Flutter and React.
Given this success, other frameworks started embracing this approach shortly. In fact, Jetpack Compose came into the spotlight fairly late unlike Apple which released SwiftUI back in September 2019.
Jetpack Compose advantages over traditional UI
Android Views are good, but not perfect. There are many irreversible technical issues that have been piling up over the years and Jetpack Compose can finally solve them as:
- Jetpack Compose is a complete redesign of Android UI built from the ground up to boost development quality and speed.
- It solves numerous issues with UI being a separate mutable entity.
- Jetpack Compose has full compatibility with XML and vice versa.
- Less code is needed.
- It fits Unidirectional Data Flow as Composables accept state and emit events.
- An unbundled toolkit so it doesn’t depend on platform releases as it was with the View Support library.
- Jetpack compose performance is great. It uses Smart recompositions, enforces a single layout pass for and gets rid of XML problems, such as View inflation.
- Learning curve. The approach is different from what developers are used to and it requires time to become familiar with the technology.
- Limited community adoption. Even though Jetpack Compose is well-received and becoming really trendy, most of the teams will rightfully prefer traditional UI with XML. Just as Kotlin didn’t gain popularity right away, Jetpack Compose will need a couple of years to become well adopted.
- Lack of documentation. A good part of Android Views is that most of the issues are probably already solved by someone or there are plenty of resources that make it possible to solve them on your own. However, it’s tricky to find everything you need with Jetpack Compose as it’s still quite fresh. Nonetheless, after the release there’s going to be far more documentation coming out.
- Fewer tools support it as it will take time for most of them to adopt the technology.
Declarative UI is a megatrend. Both Web and Mobile are actively adopting the approach. Google has made it clear that Jetpack Compose is one of the top priorities. It will take years for the technology to replace traditional XML. Many developers will stay reluctant to switch as the approach is quite different and has limited adoption yet.