Imperative programming

From Rosetta Code
Revision as of 20:01, 17 July 2008 by rosettacode>Dmitry-kazakov (Created)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Imperative programming is a programming model opposed to declarative programming. As the name suggests imperative programing instructs what to do in order to solve the problem. Declarative programming describes the problem leaving the solution to the inference system.

More formally imperative programming requires identifiable computation states, transitions between which are imperatively instructed. Declarative programming requires a well defined class of problems for which a close to optimal solution is implementable with the existing software and hardware.

The low level computational models and hardware are traditionally imperative. One exception is represented by analogue computers, which were declarative in the way they were programmed. Therefore the first generations of programming languages were imperative, as well as the precursor concept of algorithm is.

During the evolution of programming languages the computational states became more abstracted and less directly mapped to the hardware states. In the end the fourth generation of programming languages used to replace imperative programming with declarative one. This led to domain specific programming languages, because declarative programming is necessarily limited to only the problems for which the solution is known. Then the process of drifting towards declarative programming reached the equilibrium, as the maintenance of declarative solutions written in multiple languages became a problem due to the language impedance. Further, understanding of complex declarative solutions is in general more difficult, effects of errors are less predictable, performance optimization is hard etc.

Presently in the higher level languages the margin between imperative and declarative is very blurred. General purpose languages contain both imperative and declarative constructs.