Procedural programming |
Procedural programming is 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:
=Procedures and modularity=
Especially in large, complicated programs, Modularity (programming) is often a desirable property. It can be implemented using procedures that have strictly defined channels for input and output, and usually also clear rules about what types of input and output are allowed or expected. Inputs are usually specified syntactically in the form of arguments and the outputs delivered as return values .
Scope (programming) 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. This helps prevent confusion between variables with the same name being used in different places, and prevents procedures from stepping on each other s feet.
Less modular procedures, often used in small or quickly written programs tend to interact with a large number of Variables in the execution system platform, which other procedures might also modify. The fact that lots of variables act as points of contact between various parts of the program are what make it less modular.
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 code library.
(See Module (programming) and Software package.) It s very easy to understand.
=Comparison with imperative programming=
Most or all extant procedural programming languages are also imperative programming 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).
Some imperative programming forms, such as object-oriented programming, are not necessarily procedural.
=Comparison with object-oriented programming=
More sophisticated forms of modularity are possible with object-oriented programming, which is a more recent invention. Instead of dealing with procedures, inputs, and outputs, object-oriented programs pass around objects . Computation is accomplished by asking an object to execute one of its internal procedures (or one it has inherited), possibly drawing on some of its internal state.
Procedural programs are generally more computationally efficient than object-oriented programs, because there is less overhead to handle abstractions and the data structures more closely resemble the hardware that must manipulate them. Indeed, many operating systems and CPUs are designed with specific mechanisms to facilitate the efficient implementation of procedure calls.
=Procedural programming languages=
Procedural programming languages facilitate the programmer s task in following a procedural programming approach. The canonical example of a procedural programming language is ALGOL (programming language). Others include Fortran, PL/I (programming language), Modula-2 (programming language), and Ada (programming language). Note that this list includes some languages that aren t exclusively procedural, such as Java, which was designed specifically for object oriented programming.
==See also==
=External link=
|
|