Today: April 18, 2024 11:13 am
Syntax code summary - memorize and review previously learned code faster
Your menu is empty or not selected! How to config a menu

The past: about declarative and imperative

Jetpack Compose has garnered a lot of attention in the Android world since it was in alpha. And recently I got to beta – so now it’s time for all Android developers to understand what it is.

Therefore, we made a text version of Matvey Malkov’s report from our conference Mobius for Habr. Matvey works at Google UK and is personally involved in Compose, so you can learn something about the “internals” of the project from the report. But the story is not limited to this: attention is paid not only to Jetpack Compose, but to the entire declarative approach as a whole.

By the way, the Compose for Desktop project from JetBrains has also appeared recently.

In the past, there were already declarative and imperative frameworks. People often say, “Declarative is better than imperative.” In my understanding, the declarative is not better than the imperative, but loves it. These are two parts of any framework, any language. To understand why this is so, consider what declarative is.

Declarative programming is a paradigm that allows us to define programs without defining a control flow. In other words, we describe not “how”, but “what” we want to see on the screen. This is the biggest difference from imperative programming.

Here’s an example not about UI yet. The How part is an imperative story. We take var and add its values ​​in a loop. And we have “What” – declarative programming, where we say what we want to do: reduce the list using some kind of operation.

Let’s take a simpler example:

val a = 4
val b = -2
val result = a + b

Are these three lines interactive or declarative? The answer depends on which side you look at. Since we’re talking about the past, let’s remember how programming languages ​​developed.

0 Comments

No Comment.

Hello there :)

Subscribe to our newsletter!