Compare the Difference Between Similar Terms

Difference Between

Home / Technology / IT / Programming /Difference Between Declarative and Imperative Programming

Difference Between Declarative and Imperative Programming

April 6, 2018Posted byLithmee

Key Difference –声明vsImperativeProgramming

声明and imperative programming are two common programming paradigms. Thekey differencebetween Declarative and Imperative programming is that声明programming focuses on what the program should accomplish while Imperative programming focuses on how the program should achieve the result.

A programming paradigm is used to classify a programming language depending on the feature. It also allows following a certain pattern or style to solve a particular problem.

CONTENTS

1.Overview and Key Difference
2.What is Declarative Programming
3.What is Imperative Programming
4.Side by Side Comparison – Declarative vs Imperative Programming in Tabular Form
5.Summary

What is Declarative Programming?

声明programming can be explained using a real-world scenario. Assume that the user needs to check for new emails. One method is by enabling the inbox notifications. The user has to enable the notifications only once, and each time a new email arrives, he gets a notification automatically. Declarative programming is similar to that. It provides simplicity. Declarative programming expresses what required result is. It explains the logic of a computation without describing the control flow.

Difference Between Declarative and Imperative Programming

Figure 01: Programming Paradigms

An example of declarative programming is as follows. It is to multiply numbers of an array by a constant and to store them into a new array.

var numbers =[1,2,3];

var newnumbers= numbers.map(function(number){

return numbers*5;

});

Console.log(newnumbers);

In the above example, ‘map’ give instructions to iterate each item in thearrayand to invoke the call back function for each item and to store the return value to the new array. This will give the output 5,10,15. In this program, the main objective of multiply the numbers by 5 is accomplished using the map function. It will go through each element and use the call back function to calculate and store the values to the new array. It is not required to provide all the steps. The main focus is given to what should be achieved.

命令式编程是什么?

Imperative programming can be explained using a real-world scenario as before. To check the new emails, the user can login to gmail and keep refreshing the page to check whether he got new emails or not. This is similar to imperative programming. It explains each and every step involved to achieve the result. It uses statements to express the changes in the program state.

Multiplying the arrays elements with a constant and storing the values to a new array in imperative programming is as follows.

var numbers = [1,2,3];

var newnumbers= [];

for(int i=0; i< numbers.length ; i++) {

newnumbers.push(numbers[i]*5);

}

Console.log(newnumbers);

In the above example, numbers is an array. When going through the loop, each number is multiplied by 5 and added to the newnumbers array. After the end of the loop, the content of the newnumbers will print which are 5,10,15.

It can be observed that the imperative style provides all the steps to achieve the task. It expresses how to iterate through the array using ‘i’ counter variable, how many times to iterate before getting out of the loop and how to insert the calculated values to the new arrays etc.

The same problem was solved using declarative and imperative programming.

声明式和Imp的区别是什么erative Programming?

声明vs Imperative Programming

声明programming is a programming paradigm that expresses the logic of a computation without describing its control flow. Imperative programming is a programming paradigm that uses statements that changes the program’s state.
Main Focus
声明programming focuses on what the program should accomplish. Imperative programming focuses on how the program should achieve the result.
Flexibility
声明programming provides less flexibility. Imperative programming provides more flexibility.
Complexity
声明programming simplifies the program. Imperative programming can increase the complexity of the program.
Categorization
Functional, Logic, Query programming falls into declarative programming. Procedural and Object Oriented programming falls into imperative programming.

Summary – DeclarativevsImperativeProgramming

This article discussed the difference between two major programming paradigms, which are declarative and imperative programming. The difference between declarative and Imperative programming is that Declarative Programming focuses on what the program should accomplish while Imperative Programming focuses on how the program should achieve the result.

Reference:

1.“Declarative Programming.” Wikipedia, Wikimedia Foundation, 3 Apr. 2018.Available here
2.“Imperative Programming.” Wikipedia, Wikimedia Foundation, 3 Apr. 2018.Available here
3.Lecture 17 – Imperative vs Declarative Programming, Sam Nxstack, 11 Apr. 2017.Available here

Related posts:

Difference Between Functional Programming and Imperative ProgrammingDifference Between Functional Programming and Imperative Programming Difference Between Structured Programming and Object Oriented Programming Difference Between Open Source and Proprietary SoftwareDifference Between Open Source and Proprietary Software Difference Between this and super in Java_Figure 02Difference Between this and super in Java Difference Between Actual and Formal ParametersDifference Between Actual and Formal Parameters

Filed Under:ProgrammingTagged With:声明Programming,声明Programming Categorization,声明Programming Definition,声明Programming Focus,声明vs Imperative Programming,imperative programming,Imperative Programming Categorization,Imperative Programming Definition,Imperative Programming Focus

About the Author:Lithmee

Lithmee Mandula is a BEng (Hons) graduate in Computer Systems Engineering. She is currently pursuing a Master’s Degree in Computer Science. Her areas of interests in writing and research include programming, data science, and computer systems.

Leave a ReplyCancel reply

Your email address will not be published.Required fields are marked*

Request Article

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and SARS

Difference Between Coronavirus and SARS

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Covid 19

Difference Between Coronavirus and Covid 19

You May Like

Difference Between Hiking and Trekking

Difference Between Hiking and Trekking

Difference Between CentOS and RedHat

Difference Between Lycra and Neoprene

Difference Between Lycra and Neoprene

Difference Between Alternately and Alternatively

Difference Between Alternately and Alternatively

Difference Between Lobster and Shrimp

Latest Posts

  • What is the Difference Between Avobenzone and Benzene
  • What is the Difference Between Tight Junction and Adherens Junction
  • What is the Difference Between Hemorrhagic Stroke and Aneurysm
  • What is the Difference Between Zakat and Sadaqah
  • What is the Difference Between Papules and Pustules
  • What is the Difference Between Ubiquinol and CoQ10
  • Home
  • Vacancies
  • About
  • Request Article
  • Contact Us

Copyright © 2010-2018Difference Between. All rights reserved.Terms of Useand Privacy Policy:Legal.