This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: "Procedural programming" – news · newspapers · books · scholar · JSTOR (April 2008) (Learn how and when to remove this template message)

Procedural programming is a programming paradigm, classified as imperative programming,[1] that involves implementing the behavior of a computer program as procedures (a.k.a. functions, subroutines) that call each other. The resulting program is a series of steps that forms a hierarchy of calls to its constituent procedures.

The first major procedural programming languages appeared c. 1957–1964, including Fortran, ALGOL, COBOL, PL/I and BASIC.[2] Pascal and C were published c. 1970–1972.

Computer processors provide hardware support for procedural programming through a stack register and instructions for calling procedures and returning from them. Hardware support for other types of programming is possible, like Lisp machines or Java processors, but no attempt was commercially successful.[contradictory]

Development practices

Certain software development practices are often employed with procedural programming in order to enhance quality and lower development and maintenance costs.

Modularity and scoping

Modularity is about organizing the procedures of a program into separate modules -- each of which has a specific and understandable purpose.

Minimizing the scope of variables and procedures can enhance software quality by reducing the cognitive load of procedures and modules.

A program lacking modularity or wide scoping tends to have procedures that consume many variables that other procedures also consume. The resulting code is relatively hard to understand and to maintain.

Sharing

Since a procedure can specify a well-defined interface and be self-contained it supports code reuse -- in particular via the software library.

Comparison with other programming paradigms

Imperative programming

Procedural programming is classified as a imperative programming, because it involves direct command of execution.

Procedural is a sub-class of imperative since procedural includes block and scope concepts, whereas imperative describes a more general concept that does not require such features. Procedural languages generally use reserved words that define blocks, such as if, while, and for, to implement control flow, whereas non-structured imperative languages (i.e. assembly language) use goto and branch tables for this purpose.

Object-oriented programming

Also classified as imperative, object-oriented programming (OOP) involves dividing a program implementation into objects that expose behavior (methods) and data (members) via a well-defined interface. In contrast, procedural programming is about dividing the program implementation into variables, data structures, and subroutines. An important distinction is that while procedural involves procedures to operate on data structures, OOP bundles the two together. An object is a data structure and the behavior associated with that data structure.[3]

Some OOP languages support the class concept which allows for creating an object based on a definition.

Nomenclature varies between the two, although they have similar semantics:

Procedural Object-oriented
Procedure Method
Record Object
Module Class
Procedure call Message

Functional programming

The principles of modularity and code reuse in functional languages are fundamentally the same as in procedural languages, since they both stem from structured programming. For example:

The main difference between the styles is that functional programming languages remove or at least deemphasize the imperative elements of procedural programming. The feature set of functional languages is therefore designed to support writing programs as much as possible in terms of pure functions:

Many functional languages, however, are in fact impurely functional and offer imperative/procedural constructs that allow the programmer to write programs in procedural style, or in a combination of both styles. It is common for input/output code in functional languages to be written in a procedural style.

There do exist a few esoteric functional languages (like Unlambda) that eschew structured programming precepts for the sake of being difficult to program in (and therefore challenging). These languages are the exception to the common ground between procedural and functional languages.

Logic programming

In logic programming, a program is a set of premises, and computation is performed by attempting to prove candidate theorems. From this point of view, logic programs are declarative, focusing on what the problem is, rather than on how to solve it.

However, the backward reasoning technique, implemented by SLD resolution, used to solve problems in logic programming languages such as Prolog, treats programs as goal-reduction procedures. Thus clauses of the form:

H :- B1, …, Bn.

have a dual interpretation, both as procedures

to show/solve H, show/solve B1 and … and Bn

and as logical implications:

B1 and … and Bn implies H.

A skilled logic programmer uses the procedural interpretation to write programs that are effective and efficient, and uses the declarative interpretation to help ensure that programs are correct.

See also

References

  1. ^ "Programming Paradigms".
  2. ^ "Welcome to IEEE Xplore 2.0: Use of procedural programming languages for controlling production systems". Proceedings. The Seventh IEEE Conference on Artificial Intelligence Application. ieeexplore.ieee.org. doi:10.1109/CAIA.1991.120848. S2CID 58175293.
  3. ^ Stevenson, Joseph (August 2013). "Procedural programming vs object-oriented programming". neonbrand.com. Retrieved 2013-08-19.