- Get link
- Other Apps
Featured post
- Get link
- Other Apps
So I was studying RxSwift, and I found this out that
"Rx enables building apps in a declarative way.”
I didn’t pay as much attention to this, what we called as “paradigms,” cause I was used to programming step-by-step (which is imperative programming). I didn’t know this exist and I wasn’t mindful with that, but actually being aware of programming paradigms is actually helpful, so that as developers, when we code, we could be aware of what programming paradigm we should approach.
So, let’s begin,
When you research of this “Imperative and Declarative programming,” you will usually come across this similar definition, that,
Imperative programming tells us how to do it, while Declarative programming tells us what we want to happen.
So what does that mean? Let’s dive in deeper through some simple snippets
Declarative programming describes what you’re trying to accomplish without defining how to do it.
So, what did you observe?
For the first example which is an Imperative programming approach, it usually has more lines code, that’s the very obvious difference. Another is, it explicitly follows a step-by-step instruction to get the even numbers from the array. While in the declarative programming approach, it leverages an existing function, which is filter.
Imperative Programming provides flexibility but brings in complexity, Declarative programming hides complexity and provides simplicity
Programming Languages that apply imperative and declarative programming
Imperative Programming Languages | Declarative Programming Languages |
C
C#
Java
|
SQL
And there’s a bunch of other languages which I’m not familiar with
|
So going back to my research when I was learning RxSwift,
If Swift is an imperative language, and RxSwift allows us to code in a declarative way, how could that happen?
Basically, Declarative programming is an abstraction of functions that underlying it is an imperative implementation.
This kind of programming usually is much safer and regulated, allowing us programmers to write an easy to understand code.
So even though some languages are imperative, we could still code in a declarative way, so that when we program as team, it allows us to code in a much safer and scalable way.
Comments
Post a Comment