Imperative Programming as the name suggests is a type of programming
paradigm that describes how the program executes. Developers are more
concerned with how to get an answer step by step. It comprises the sequence
of command imperatives. In this, the order of execution is very important and
uses both mutable and immutable data. Fortran, Java, C, C++ programming
languages are examples of imperative programming.
Declarative Programming as the name suggests is a type of programming
paradigm that describes what programs to be executed. Developers are more
concerned with the answer that is received. It declares what kind of results we
want and leave programming language aside focusing on simply figuring out
how to produce them. In simple words, it mainly focuses on end result. It
expresses the logic of computation. Miranda, Erlang, Haskell, Prolog are a few
popular examples of declarative programming.
After getting the basics of understanding of both the languages now let us do
discuss the key differences between these two different types of programming
Imperative Programming
Declarative Programming
In this, programs specify how it is to In this, programs specify what is to be
be done. done.
It simply describes the control flow It simply expresses the logic of
of computation. computation.
Its main goal is to describe the desired
Its main goal is to describe how to
result without direct dictation on how to get
get it or accomplish it.
it.
Imperative Programming
Declarative Programming
Its advantages include ease to learn Its advantages include effective code,
and read, the notional model is which can be applied by using ways, easy
simple to understand, etc. extension, high level of abstraction, etc.
Its type includes procedural
programming, object-oriented Its type includes logic programming and
programming, parallel processing functional programming.
approach.
In this, the user is allowed to make
In this, a compiler is allowed to make
decisions and commands to the
decisions.
compiler.
It has many side effects and
It has no side effects and does not include
includes mutable variables as
any mutable variables as compared to
compared to declarative
imperative programming.
programming.
It gives full control to developers
It may automate repetitive flow along with
that are very important in low-level
simplifying code structure.
programming.
In imperative programming, the In declarative programming, the system
programmer is responsible for optimizes the code based on the rules and
optimizing the code for performance constraints specified by the programmer.
In imperative programming, In declarative programming, variables are
variables can be mutable. typically immutable.