Jetpack Compose
Juan Carlos Garrote Android developer

Jetpack Compose: declarative paradigm comes to native Android development

In recent times, the development of applications - not only mobile applications - has modernised very quickly. While on other platforms there was already an approach to the development of user interfaces using a declarative paradigm (Swift UI for iOS, Flutter for multiplatform, among others), in July 2021 a stable version of the tool that allows this type of programming to be introduced natively on Android was finally released: Jetpack Compose.

But why are this trend so successful, what advantages does it have over the traditional imperative paradigm, and is it really the future of user interface development?

Imperative vs. declarative paradigm

In order to be able to go deeper into the tool in question, it is necessary to start with the basics: the functioning of the two basic paradigms with which to build the graphic part of the applications.

In a user interface developed with the imperative paradigm, each of the components that are candidates for change must be told how it must behave in response to each event or interaction that occurs, in order to modify its internal state. In other words, building a user interface through imperative programming implies indicating how it should behave at each moment, with each event that occurs.

With a declarative paradigm, components do not have internal state, but every time the state of the application is updated in response to events or interactions, they are built anew with a different appearance if necessary. In other words, building a user interface through declarative programming means indicating what should be displayed in the user interface based on the current state of the application.

Defining user interfaces declaratively has an important advantage over defining them imperatively. In an imperative paradigm, as mentioned above, components must be manipulated every time an event occurs. Manually modifying components increases the likelihood of errors, since the more components that need to be kept up to date, the more complex it is to maintain a consistent state, thus impairing the maintainability of the system. Therefore, the advantage offered by the declarative paradigm is that it is not necessary to manipulate these components, but by indicating from the beginning what should be displayed based on the current state, the user interface is completely regenerated automatically when a change of state occurs, thus carrying out a rebuilding. This greatly simplifies the UI update process, since with each rebuilding the user interface will be generated in the correct state without the need to manipulate its components, thereby reducing the likelihood of errors.

Jetpack Compose benefits

Jetpack Compose is a modern toolkit for native development of user interfaces in Android applications through a declarative API. It can be used exclusively with the Kotlin programming language, although it has interoperability with the XML view system still used in Android, which makes it more flexible.

Jetpack Compose is a tool that has come on strong and in the short time it has been on the market, it has demonstrated clear advantages when it comes to developing applications

All this, Jetpack Compose offers a benefit in four main aspects compared to the development of user interfaces using XML and imperative paradigm:

  • Less code. One of the things Jetpack Compose excels at is the need for fewer lines of code to create the same thing as would be done by imperative programming. This is a clear advantage when it comes to maintaining the system.
  • More intuitive. Being a declarative paradigm, which is based on simply making a description of the user interface to be displayed, the code is considered to be much more readable and understandable for developers.
  • Accelerates development. Due to the reduced complexity in development and maintenance that this tool provides, creating applications is more straightforward, thus shortening the time needed to develop them.
  • Power. Since everything is developed entirely in Kotlin, it is possible to take advantage of all the power offered by the language to create dynamic views that would not be possible only with the use of XML. In addition, it applies the Material Design style guides by default, so you don't have to worry too much about whether you are following these design principles.

Success stories

In case it wasn't already clear, yes, many well-known Android apps are already switching to Jetpack Compose in search of the efficiency it promises. Some of these cases are high-profile, involving apps with several million or even billions of downloads:

  • Twitter. The social network of the blue bird was the first to make the switch to Jetpack Compose. After making the switch, the Twitter team claims to have "increased efficiency and speed in development, as well as making its application much more robust than it was before".
  • Square. One of the most famous POS in the market also decided to move to this new tool. This has allowed them to "focus on the important things in a much simpler way".
  • Monzo. This UK mobile app-based bank, with millions of users worldwide, was another bank that decided to switch to Jetpack Compose for its Android app. According to them, "creating a high-quality app was an easy task with Jetpack Compose".

Conclusion

Jetpack Compose is a tool that has come on strong and in the short time it has been on the market, it has demonstrated clear advantages when it comes to developing applications. In general terms, it is possible to see how the development and maintenance process of systems that have implemented this paradigm has improved, making it noticeable for both developers and end users. Best of all: this is just the beginning, will Jetpack Compose surprise us even more in the future? Talk?