Imperative vs Declarative Languages ..

Table of contents

No heading

No headings in the article.

Most of us know the number of programming languages like Javascript, Cpp, Java and many more, but we often don't know under which category these languages fall. So Let's deep dive into 2 types of programming languages:-

Imperative vs Declarative Languages:

The clarification is based on how languages take input from user to perform an action:-

IMPERATIVE LANGUAGES:- In this category of languages we need to specify the work which we want to be done. For instance, you wanna write a table of 10, so what you gonna do is to declare a variable and then take an input for the variable followed by a loop on the variable which will iterate from 1-10, and lastly you print the table. Considering another example of sorting 2 or more than 2 values we need to specify the steps/algorithms for bubble sort, insertion sort, etc in order to sort the values. So in a nutshell we need to specify/describe the steps for the work which we want to be done. So these types of languages come under IMPERATIVE LANGUAGES. Languages that fall under this category are JavaScript, C++, Python, Java, and many more.

Declarative Languages:- Unlike Imperative Languages we don't need to specify the steps for the work which we want to be done. As the name suggests "declarative" means we just declare our end goal and the steps are already built in the language. The language itself figures out the steps and provides the output accordingly. The commonly used declarative language is SQL. Considering an example of sorting two or more values in ascending order, you don't need to apply bubble sort or any other sorting technique. Instead, you can simply declare or write a query/statement, and the language will provide the sorted data.

Hope this helps !!