Procedural programming: Difference between revisions

Content deleted Content added
Modulatum (talk | contribs)
m Reverted 1 edit by 1.46.24.167 (talk) to last revision by Graham87
 
(488 intermediate revisions by more than 100 users not shown)
Line 1:
{{Short description|Computer programming paradigm}}
{{unreferenced||date=June 2006}}
{{About|the computer programming paradigm|the method of algorithmic content creation|Procedural generation}}
{{More citations needed|date=April 2008}}
 
'''Procedural programming''' is a [[programming paradigm]], classified as [[imperative programming]],<ref>{{cite web |url=https://cs.lmu.edu/~ray/notes/paradigms/ |title=Programming Paradigms
{{otheruses4|the computer programming paradigm|the method of algorithmic content creation| procedural generation}}
}}</ref> that involves implementing the behavior of a [[computer program]] as [[Function (computer programming)|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 {{circa|1957}}–1964, including [[Fortran]], [[ALGOL]], [[COBOL]], [[PL/I]] and [[BASIC]].<ref name=":0">{{cite conference
'''Procedural programming''' can sometimes be 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, [[subroutine]]s, 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.
|book-title=Proceedings. The Seventh IEEE Conference on Artificial Intelligence Application
|title=Welcome to IEEE Xplore 2.0: Use of procedural programming languages for controlling production systems
|publisher=[[IEEE]]
|doi=10.1109/CAIA.1991.120848
|s2cid=58175293
}}</ref> [[Pascal (programming language)|Pascal]] and [[C (programming language)|C]] were published {{circa|1970}}–1972.
 
[[Computer processor]]s provide hardware support for procedural programming through a [[stack register]] and instructions for [[Subroutine#Jump to subroutine|calling procedures]] and returning from them. Hardware support for other types of programming is possible, like [[Lisp machines]] or [[Java processor]]s, but no attempt was commercially successful.{{Contradictory inline|article=Java processor|reason=It says they are today the most popular form of a high-level language computer architecture.|date=October 2017|section=}}
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:
 
== Development practices ==
* 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 [[spaghetti code]]).
* The ability to be strongly modular or [[structured programming|structured]].
 
Certain [[software development]] practices are often employed with procedural programming in order to enhance quality and lower development and maintenance costs.
== Procedures and modularity ==
 
===Modularity and scoping===
[[Modularity (programming)|Modularity]] is generally desirable, especially in large, complicated programs. Inputs are usually specified syntactically in the form of ''arguments'' and the outputs delivered as ''return values''.
 
[[modularity (programming)|Modularity]] is about organizing the procedures of a program into separate modules—each of which has a specific and understandable purpose.
[[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.
 
Minimizing the [[scoping|scope]] of variables and procedures can enhance software quality by reducing the [[cognitive load]] of procedures and modules.
Less modular procedures, often used in small or quickly written programs, tend to interact with a large number of [[variable]]s in the execution [[system platform|environment]], which other procedures might also modify.
 
A program lacking modularity or wide scoping tends to have procedures that consume many [[variable (programming)|variable]]s that other procedures also consume. The resulting code is relatively hard to understand and to maintain.
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|programming libraries]].
 
===Sharing===
(See [[Module (programming)]] and [[Software package]].)
 
Since a procedure can specify a well-defined interface and be self-contained it supports [[code reuse]]—in particular via the [[Library (computing)|software library]].
== Comparison with imperative programming ==
 
== Comparison with other programming paradigms ==
Most procedural programming languages are also [[imperative programming|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 register]]s) to something like the position of the "turtle" in the [[Logo programming language]].
 
=== Comparison with object-orientedImperative programming ===
 
Procedural programming is classified as an [[imperative programming]], because it involves direct command of execution.
The focus of procedural programming is to break down a programming task into a collection of [[data structures]] and [[subroutines]], whereas in [[object oriented programming]] it is to break down a programming task into [[Object (computer science)|object]]s. 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.)
 
Procedural is a sub-class of imperative since procedural includes [[Block (programming)|block]] and [[Scope (computer science)|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 <code>if</code>, <code>while</code>, and <code>for</code>, to implement [[control flow]], whereas [[non-structured programming|non-structured]] imperative languages (i.e. [[assembly language]]) use [[goto]] and [[branch table]]s for this purpose.
The most popular programming languages usually have both OOP and procedural aspects.
 
=== Object-oriented programming ===
Some differences between pure object-oriented languages and non-OO procedural languages:
 
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 [[variable (programming)|variables]], [[data structure]]s, and [[subroutine]]s. 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.<ref>{{cite web
|url=http://neonbrand.com/procedural-programming-vs-object-oriented-programming-a-review/
|title=Procedural programming vs object-oriented programming
|publisher=neonbrand.com
|access-date=2013-08-19
|last=Stevenson
|first=Joseph
|date=August 2013
}}</ref>
 
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:
 
{| class="wikitable"
|-
! width=5033% |pure OOProcedural
! width=33% |Object-oriented
! pure procedural
|-
| Procedure
| methods
| [[Method (computer science)|Method]]
| functions
|-
| [[Record (computer science)|Record]]
| objects
| modulesObject
|-
| messageModule
| callClass
|-
| Procedure call
| attribute<!-- member = methos + attribute -->
| Message
| variable
|}
 
=== Comparison with logicFunctional programming ===
 
The principles of modularity and code reuse in [[functional programming|functional]] languages are fundamentally the same as in procedural languages, since they both stem from [[structured programming]]. For example:
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.
* Procedures correspond to functions. Both allow the reuse of the same code in various parts of the programs, and at various points of its execution.
* By the same token, procedure calls correspond to function application.
* Functions and their modularly separated from each other in the same manner, by the use of function arguments, return values and variable scopes.
 
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 function]]s:
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:
* Whereas procedural languages model execution of the program as a sequence of imperative commands that may implicitly alter shared state, functional programming languages model execution as the evaluation of complex expressions that only depend on each other in terms of arguments and return values. For this reason, functional programs can have a free order of code execution, and the languages may offer little control over the order in which various parts of the program are executed; for example, the arguments to a procedure invocation in [[Scheme (programming language)|Scheme]] are evaluated in an arbitrary order.
* Functional programming languages support (and heavily use) [[first-class function]]s, [[anonymous function]]s and [[Closure (computer programming)|closures]], although these concepts have also been included in procedural languages at least since [[Algol 68]].
* Functional programming languages tend to rely on [[tail call optimization]] and [[higher-order function]]s instead of imperative looping constructs.
 
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.
:<tt>H :- B<sub>1</sub>, …, B<sub>n</sub>.</tt>
 
There do exist a few [[esoteric programming language|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.
have a dual interpretation, both as procedures
 
=== Logic programming ===
:to show/solve <tt>H</tt>, show/solve <tt>B<sub>1</sub></tt> and … and <tt>B<sub>n</sub></tt>
 
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 programming|declarative]], focusing on what the problem is, rather than on how to solve it.
and as logical implications:
 
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:
:<tt>B<sub>1</sub> and … and B<sub>n</sub> implies H</tt>.
 
:{{mono|1=H :- B<sub>1</sub>, …, B<sub>n</sub>.}}
Experienced logic programmers use the procedural interpretation to write programs that are effective and efficient, and they use the declarative interpretation to help ensure that programs are correct.
 
have a dual interpretation, both as procedures
== Procedural programming languages ==
 
:to show/solve {{mono|1=H}}, show/solve {{mono|1=B<sub>1</sub>}} and … and {{mono|1=B<sub>n</sub>}}
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 (programming language)|ALGOL]].
 
and as logical implications:
Languages in which the only form of procedure is a [[method (computer science)|method]] are generally considered object-oriented rather than procedural, and are not included in this list. This applies, in particular, to [[C Sharp (programming language)|C#]] and [[Java (programming language)|Java]].
 
:{{mono|1=B<sub>1</sub> and … and B<sub>n</sub> implies H}}.
Languages, like [[Prolog]] and its variants, which are both declarative and procedural, are also not included.
 
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.
* [[Ada programming language|Ada]]
* [[ALGOL (programming language)|ALGOL]]
* [[Active Server Pages|ASP]]
* [[BASIC programming language|BASIC]]
* [[C (programming language)|C]]
<!-- C# is OO rather than procedureal -->
<!-- * [[C++]] -->
* [[ColdFusion]]
* [[COBOL]]
* [[Component Pascal]]
* [[D programming language|D]]
<!-- * [[Delphi programming language|Delphi]] Delphi is a hybrid language like C++, not procedural -->
* [[ECMAScript]] (e.g., [[ActionScript]], [[DMDScript]], [[JavaScript]], [[JScript]], [[Visual Basic]])
* [[Forth (programming language)|Forth]]
* [[Fortran]]
* [[F programming language|F]]
<!-- Java is OO rather than procedureal -->
* [[Lasso programming language|Lasso]]
* [[Linoleum programming language|Linoleum]]
* [[Maple computer algebra system|Maple]]
* [[Mathematica]]
* [[MATLAB]]
* [[Modula-2]]
* [[Oberon (programming language)|Oberon]] (Oberon-1 and Oberon-2)
* [[Occam programming language|Occam]]
* [[MUMPS|M]]
* [[Neko (programming language)|Neko]]
* [[Pascal programming language|Pascal]]
* [[Perl]]
* [[PHP]]
* [[Pike (programming language)|Pike]]
* [[PL/C]]
* [[Python (programming language)|Python]]
* [[PL/I]]
* [[Rapira]]
* [[RPG_programming_language|RPG]]
* [[Tcl]]
* [[VBScript]]
 
== List of Popular Software written using Procedural Programming ==
 
===System Software===
 
* [[Linux Kernel]]
 
===Games===
 
* ''[[Doom (video game)|Doom]]''
* ''[[Doom II: Hell on Earth]]''
* ''[[Quake]]''
* ''[[Quake II]]''
* ''[[Quake III Arena]]''
* ''[[Spore (video game)|Spore]]''
 
===Emulators===
 
*[[Zsnes|Zsnes]]
*[[MAME|MAME]]
*VGB
*iNES
*VGBA
*[[fMSX|fMSX]]
*MG
*Speccy
 
===Applications===
 
* [[Apache HTTP Server|Apache Server]]
* [[PostgreSQL|PostgreSQL]]
* [[Python programming language|Python Interpreter]]
* [[Ruby programming language|Ruby Interpreter]]
* [[Perl|Perl Interpreter]]
* [[PHP|PHP Interpreter]]
* [[Samba (software)|Samba]]
 
== See also ==
* [[Declarative programming]]
 
* [[Functional programming]] (contrast)
* [[Imperative programming]]
* [[Logic programming]]
* [[Object-oriented programming]]
* [[Programming paradigm]]s
* [[Programming language]]
* [[Procedural generation]] (contrast)
* [[Structured programming]]
* [[SQL#Procedural extensions|SQL procedural extensions]]
 
==References==
{{reflist}}
 
== External links ==
 
{{Programming paradigms navbox}}
* [http://dmoz.org/Computers/Programming/Languages/Procedural/ Open Directory: Programming: Languages: Procedural]
{{Types of programming languages}}
 
{{Programming language}}
[[Category:Programming paradigms]]
 
[[be-x-old:Працэдурнае праграмаванне]]
[[de:Prozedurale Programmierung]]
[[el:Διαδικαστική γλώσσα προγραμματισμού]]
[[fr:Programmation procédurale]]
[[ko:절차적 프로그래밍]]
[[he:תכנות פרוצדורלי]]
[[ja:手続き型プログラミング]]
[[pl:Programowanie proceduralne]]
[[pt:Programação procedural]]
[[ru:Процедурное программирование]]
[[vi:Lập trình thủ tục]]
[[tr:Yordamsal programlama]]
[[uk:Процедурне програмування]]