Imperative & Declarative Approach

App Devops
2 min readAug 23, 2022

Imperative Approach:

Imperative programming focuses on how to perform a task. It places a greater emphasis on how the operations are carried out rather than what procedures are carried out. The prototype of an app’s UI will be independent(separate) in imperative UI programming.

Examples of imperative approaches: XML layouts in Android, storyboards in iOS.

The imperative style specifies step-by-step procedures that helps to build the app. Programs that follow imperative programming approach are more flexible and complex. Both procedural and OOPs are imperative programming techniques.

The imperative approach outlines all the steps inside the functions/procedure. In this approach, how things are done is more significant, so the developer mentions all the steps involved.

Here in this example, steps involved in populating the ListView are mentioned. We first create a custom adapter and then inflate the ListView with a custom layout.

Declarative approach :

The Declarative approach focuses on what a program should achieve. It offers less flexibility.

Examples of declarative approach: Jetpack Compose, SwiftUI and Flutter.

This programming methodology deals with the logic behind the computation without describing its control flow, which makes the program simple. The Declarative approach incorporates query, logic and functional programming that focuses on the result.

The declarative framework uses imperative styles internally in order to define the functions. ​​​​​​​One of the most significant advantages of the declarative approach is that it allows the developer to focus on the real solution of the app rather than the code setup.

Benefits:

1. Enhances readability of the program

2. Reusability

3. Concise way of programming

--

--