Saturday, March 06, 2010

Declarative Programming Vs Imperative Programming

principal distinction between declarative languages and imperative languages is that declarative languages allow the programmer to concentrate on the logic of an algorithm (declarative languages are goal driven, control is not the concern of the programmer), while imperative languages require the programmer to focus on both the logic and control of an algorithm.

Characteristics of imperative languages:

1. Model of computation based on a step by step sequences of commands.
2. Program states exactly how the result is to be obtained.
3. Destructive assignment of variables.
4. Data structures changed by successive destructive assignments.
5. Order of execution is crucial, commands can only be understood in context of previous computation due to side effects.
6. Expressions/definitions cannot be used as values.
7. Control is the responsibility of the programmer.

Characteristics of declarative languages:

1. Model of computation based on a system where relationships are specified directly in terms of the constituents of the input data.
2. Made up of sets of definitions or equations describing relations which specify what is to be computed, not how it is to be computed.
3. Non-destructive assignment of variables.
4. Explicit representations for data structures used.
5. Order of execution does not matter (no side effects).
6. Expressions/definitions can be used as values.

You can get more info here.