Imperative Programming - Imperative, Procedural, and Declarative Programming

Imperative, Procedural, and Declarative Programming

Procedural programming is imperative programming in which the program is built from one or more procedures (also known as subroutines or functions). The terms are often used as synonyms, but the use of procedures has a dramatic effect on how imperative programs appear and how they are constructed. Heavily procedural programming, in which state changes are localized to procedures or restricted to explicit arguments and returns from procedures, is known as structured programming. From the 1960s onwards, structured programming and modular programming in general, have been promoted as techniques to improve the maintainability and overall quality of imperative programs. Object-oriented programming extends this approach.

Procedural programming could be considered as a step towards declarative programming. A programmer can often tell, simply by looking at the names, arguments and return types of procedures (and related comments), what a particular procedure is supposed to do - without necessarily looking at the detail of how the procedure achieves its result. At the same time, a complete program is still imperative since it 'fixes' the statements to be executed and their order of execution to a large extent.

Declarative programming is a non-imperative style of programming in which programs describe the desired results of the program, without explicitly listing command or steps that need to be carried out to achieve the results. Functional and logical programming languages are characterized by a declarative programming style.

In a pure functional language, such as Haskell, all functions are without side effects, and state changes are only represented as functions that transform the state. Although pure functional languages are non-imperative, they often provide a facility for describing the effect of a function as a series of steps. Other functional languages, such as Lisp, OCaml and Erlang, support a mixture of procedural and functional programming.

In logical programming languages, programs consist of logical statements, and the program executes by searching for proofs of the statements. As in functional programming languages, some logical programming languages such as Prolog, and database query languages such as SQL, while declarative in principle, also support a procedural style of programming.

Many imperative programming languages (such as Fortran, BASIC and C) are abstractions of assembly language.

Read more about this topic:  Imperative Programming

Famous quotes containing the word programming:

    If there is a price to pay for the privilege of spending the early years of child rearing in the driver’s seat, it is our reluctance, our inability, to tolerate being demoted to the backseat. Spurred by our success in programming our children during the preschool years, we may find it difficult to forgo in later states the level of control that once afforded us so much satisfaction.
    Melinda M. Marshall (20th century)