Mobile Apps — The Declarative Mindset

Rohit Kelkar
Globant
Published in
3 min readJun 30, 2022

Hello readers!!

Hope you are keeping well with all the buzz around the new and trendy set of frameworks, and newer announcements around the existing mobile application technologies.

As the mobile application development technology stack is evolving in all possible directions, right from the recent enhancements to native tech like Swift to the addition of SwiftUI, the introduction of Jetpack Compose for Android Native to the different cross-platform technologies like Flutter, ReactNative, and Xamarin(let's call it MAUI now if you know), things have been changing, updating and evolving for good. And that's what I am going to share my thoughts on, having tried my hands-on experience with different candidates for mobile app development.

Source — Google Images

There’s a shift happening in how mobile apps are built — again. Now, we’re seeing a transition from imperative to declarative UI frameworks in the form of SwiftUI, Jetpack Compose, ReactNative, Flutter, and Xamarin MAUI.

We are aware of the imperative style of programming to code mobile apps for Android and iOS. However, the newer declarative UI requires thinking about app development from a new and different perspective. In a declarative framework, changes in state trigger a rebuild of the UI, which removes a whole category of state-related bugs and makes it easier to reason about updates. You define what the UI should look like for a given state for a given time, and the framework figures out how to do it using sensible defaults and context.

Source — Medium

UI = f(state), where f represents the build methods. If something changes the app’s state, the UI will be redrawn based on f and the new state.

Let's check some samples from different languages available for mobile apps.

SwiftUI :

import SwiftUI  // using the SwiftUI framework

struct ContentView : View {
var body : some View {
Text("Hello, world!")
.padding()
}
}

Flutter :

Widget build(BuildContext context) { //everything is a widget
return Container(
decoration: const BoxDecoration(color: Colors.white),
child: const Center(
child: Text(
'Hello World',
textDirection: TextDirection.ltr,
style: TextStyle(
fontSize: 32,
color: Colors.black87,
),
),
),
);
}

Xamarin :

using Xamarin.Forms.Markup;

public partial class SearchPage
{
void Build() => Content =
new StackLayout { Children = {
Header,
}};
Label Header => new Label { Text = "Hello world" };
}

How does it benefit the developer community and teams of all sizes and skills?

Well, here is a way to look at it. With all the frameworks and technologies adopting the declarative style of coding mobile apps, it becomes very easier for people with different skills to make their contributions. For example, if an iOS developer is away and someone needs to fill the spot for time being and if an Android developer, who is also used to the declarative style of programming can understand and contribute even if he had never written a line of Swift code in his lifetime. Similarly, someone working on Flutter or Xamarin, already used to the declarative style can step in easily.

While this might look a bit blurry at the moment but once there is a paradigm shift from imperative to declarative programming for mobile apps, this sounds very promising. Apple and Google are the trendsetters in mobile app development and since they are both working so much on their own declarative UI frameworks, it’s clear that they want to push things in that direction, or, at least, to give developers another solid option.

With similar languages and the declarative approach to building UI, it’s much easier for teams to use the same architecture. For someone like me having experience working with Xamarin, Flutter, and now syncing up with SwiftUI, learning and trying out different technologies has been easy because of the similarity in code structure.

To sum this up, I think the declarative mindset is here to stay! And no matter which technology you work on, be it Native Android, iOS, or Cross-platform, developing and adapting to this newer mindset is going to be crucial and of great help going forward.

--

--