Subscribe by Email


Saturday, May 22, 2010

Imperative Programming and differences between Imperative and Functional Programming

Imperative programming is characterized by programming with a state and commands which modify the state.
- Imperative: a command or order.
- Procedure: the act, method or manner of proceeding in some process or course of action a particular course of action or way of doing something.
When imperative programming is combined with subprograms it is called procedural programming.

The imperative programming paradigm is an abstraction of real computers which in turn are based on the Turing machine and the Von Neumann machine with its registers and store (memory). At the heart of these machines is the concept of a modifiable store. Variables and assignments are the programming language analog of the modifiable store. The store is the object that is manipulated by the program. Imperative programming languages provide a variety of commands to provide structure to code and to manipulate the store.
In imperative programming, a name may be assigned to a value and later reassigned to another value. The collection of names and the associated values and the location of control in the program constitute the state. The state is a logical model of storage which is an association between memory locations and values.

Characteristic : Programmer focus
- Imperative approach: How to perform tasks (algorithms) and how to track changes in state.
- Functional approach: What information is desired and what transformations are required.
Characteristic : State changes
- Imperative approach: Important.
- Functional approach: Non-existent.
Characteristic : Order of execution
- Imperative approach: Important.
- Functional approach: Low priority.
Characteristic : Primary flow control
- Imperative approach: Loops, conditionals, and function (method) calls.
- Functional approach: Function calls, including recursion.
Characteristic : Primary manipulation unit
- Imperative approach: Instances of structures or classes.
- Functional approach: Functions as first-class objects and data collections.


No comments:

Facebook activity