Procedural programming
From Wikipedia, the free encyclopedia
Procedural programming is sometimes used as a synonym for imperative programming (specifying the steps the program must take to reach the desired state), but can also refer (as in this article) to a programming paradigm based upon the concept of the procedure call. Procedures, also known as routines, subroutines, methods, or functions (not to be confused with mathematical functions, but similar to those used in functional programming) simply contain a series of computational steps to be carried out. Any given procedure might be called at any point during a program's execution, including by other procedures or itself.
Procedural programming is often a better choice than simple sequential or unstructured programming in many situations which involve moderate complexity or which require significant ease of maintainability. Possible benefits:
- The ability to re-use the same code at different places in the program without copying it.
- An easier way to keep track of program flow than a collection of "GOTO" or "JUMP" statements (which can turn a large, complicated program into so-called "spaghetti code").
- The ability to be strongly modular or structured.
Contents |
[edit] Procedures and modularity
Especially in large, complicated programs, modularity is generally desirable.Inputs are usually specified syntactically in the form of arguments and the outputs delivered as return values.
Scoping is another technique that helps keep procedures strongly modular. It prevents the procedure from accessing the variables of other procedures (and vice-versa), including previous instances of itself, without explicit authorization.
Less modular procedures, often used in small or quickly written programs, tend to interact with a large number of variables in the execution environment, which other procedures might also modify.
Because of the ability to specify a simple interface, to be self-contained, and to be reused, procedures are a convenient vehicle for making pieces of code written by different people or different groups, including through programming libraries.
(See Module (programming) and Software package.)
[edit] Comparison with imperative programming
Most or all existent procedural programming languages are also imperative languages, because they make explicit references to the state of the execution environment. This could be anything from variables (which may correspond to processor registers) to something like the position of the "turtle" in the Logo programming language (which could be anything from a cursor on the screen to an actual device which moves around on the floor of a room).
[edit] Comparison with object-oriented programming
The focus of procedural programming is to break down a programming task into a collection of data structures and routines, whereas in object oriented programming it is to break down a programming task into objects. Either method can be valid for accomplishing a specific programming task. ( Object orientation is often referred to as OO and object oriented programming as OOP. )
The most popular programming languages usually have both OOP and procedural aspects.
Some differences between pure OO languages and non-OO Procedural Languages:
pure OO | pure procedural |
---|---|
methods | functions |
objects | modules |
message | call |
member | variable |
It is said that object oriented programming can be taught more easily to non-technical persons, because it fits better with the mental model of the world. This is speculative because psychologists are still unsure how the exact human model of the world can be represented. When the steam engine was invented, the human mind was compared to it. When the computer was invented, the human mind was compared to it. When OOP was invented, the human mind was compared to it.
Another important difference between OO and non-OO languages is that OO languages that need database access also need to map the common relational database model to their own class structure.
[edit] Procedural programming languages
To be considered procedural, a programming language should support procedural programming by having an explicit concept of a procedure, and a syntax to define it.
The canonical example of a procedural programming language is ALGOL. A language in which the only form of procedure is a method is generally considered object-oriented rather than procedural, and will not be included in this list. This applies to C# and Java, but not to C++.
- Ada
- ALGOL
- BASIC
- C
- C++
- ColdFusion
- COBOL
- Component Pascal
- D
- Delphi
- ECMAScript (e.g., ActionScript, DMDScript, JavaScript, JScript)
- Forth
- Fortran
- Lasso
- Linoleum
- Maple
- Mathematica
- MATLAB
- Modula-2
- Oberon (Oberon-1 and Oberon-2)
- Occam
- M
- Pascal
- Perl
- PHP
- PL/C
- Python
- PL/I
- Rapira
- VBScript
- Visual Basic
[edit] Popular Software written using Procedural Programming
[edit] See also
- Functional programming (contrast)
- Imperative programming
- Object-oriented programming
- Programming paradigms
- Programming language
- Procedural generation (contrast)
- Structured programming