Declarative Programming Paradigm

Declarative Programming Paradigm

Declarative Programming Paradigm is a programming style which focuses on what to do rather than how to do it. When defined in contrast with Imperative Paradigm, declarative style describes what a computation should perform without having the step-by-step logic on how to perform it. They are not always Turing-Complete.

The below are few languages that follows Declarative Programming Paradigm

Examples

Querying with SQL

CREATE TABLE user (
    userId int,
   firstName varchar(255),
   lastName varchar(255),
);

The above query is a simple SQL query to create a table user. We can easily understand what is happening by just reading out the query. This is declarative as we are declaring what to do rather than writing the step-by-step logic to retrieve the data.

One more query

SELECT firstName FROM user;

Similar to above explanation, this query also says what to do. We tell what to do, i.e., select the data from column firstName from the table user without telling how to do it.

Example with HTML

Here is one of my favorite examples. The below is a snippet of HTML code we write to import an image.

<img src="geeks_clan.jpg" alt="Geeks Clan <3" width="500" height="600">

We can understand the above line just by reading it out. We are adding an image from source src with the given alt text, width and height. Here, we tell the browser what to do. We tell it to pick the image geeks_clan.jpg set the size to 500x600 and add the alt text Geeks Clan <3. We do not tell the browser how to do it.

I hope this post gave you people more insight on what is Declarative Programming Paradigm. Do share it with others and support us ☺

error

Enjoy this blog? Please spread the word :)