Declarative User Interfaces
What is it now, again?
To those who haven’t heard of it, yet, let’s briefly elaborate what Jetpack Compose actually is. It’s a method of implementing your UI in a declarative way. You no longer need to write layout XML files and view classes. With Jetpack Compose this comes all together – directly in your codebase. You use Kotlin as a language to describe (declare/compose) your UI – all broken down into small digestible components.
Hmm... does this sound familiar to you? Happen to be an iOS or React developer? Or cross-platform with Xamarin, Flutter? Or even QML? Basically, all the big players in modern programming technologies have already started the transition to declarative UI – for good reasons.
But before we continue with our topic of UI development, let’s take a step back and have a closer look at the differ ences between declarative and imperative programming to get the full picture.
Declarative vs. imperative programming
Think about your favorite programming language which you probably use on a daily basis. Does it support declarative or imperative programming? Have you ever thought about it? Probably not. The answer is pretty surprising: Most modern languages equally support both! Imperative and declarative programming are pro gramming paradigms – they do not rule out each other. But of course, they are not the same. So, let’s have a look at the differences.
Here’s a simple example. We want to calculate the sum of a list of numbers. The following code snippet demon strates how to imperatively implement sum in TypeScript.
Read the whole article in the new UXMA Trend Report 2022!