Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Procedural programming

From Wikipedia, the free encyclopedia
Computer programming paradigm
This article is about the computer programming paradigm. For the method of algorithmic content creation, seeProcedural generation.
This articleneeds additional citations forverification. Please helpimprove this article byadding 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 message)

Procedural programming is aprogramming paradigm, classified asimperative programming,[1] that involves implementing the behavior of acomputer program asprocedures (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 appearedc. 1957–1964, includingFortran,ALGOL,COBOL,PL/I andBASIC.[2]Pascal andC were publishedc. 1970–1972.

Computer processors provide hardware support for procedural programming through astack register and instructions forcalling procedures and returning from them. Hardware support for other types of programming is possible, likeLisp machines orJava processors, but no attempt was commercially successful.[contradictory]

Development practices

[edit]

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

Modularity and scoping

[edit]

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

Minimizing thescope of variables and procedures can enhance software quality by reducing thecognitive load of procedures and modules.

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

Sharing

[edit]

Since a procedure can specify a well-defined interface and be self-contained it supportscode reuse—in particular via thesoftware library.

Comparison with other programming paradigms

[edit]

Imperative programming

[edit]

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

Procedural is a sub-class of imperative since procedural includesblock andscope concepts, whereas imperative describes a more general concept that does not require such features. Procedural languages generally use reserved words that define blocks, such asif,while, andfor, to implementcontrol flow, whereasnon-structured imperative languages (i.e.assembly language) usegoto andbranch tables for this purpose.

Object-oriented programming

[edit]

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 intovariables,data structures, andsubroutines. 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:

ProceduralObject-oriented
ProcedureMethod
RecordObject
ModuleClass
Procedure callMessage

Functional programming

[edit]

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

  • 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 ofpure functions:

  • 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 inScheme are evaluated in an arbitrary order.
  • Functional programming languages support (and heavily use)first-class functions,anonymous functions andclosures, although these concepts have also been included in procedural languages at least sinceAlgol 68.
  • Functional programming languages tend to rely ontail call optimization andhigher-order functions 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 forinput/output code in functional languages to be written in a procedural style.

There do exist a fewesoteric functional languages (likeUnlambda) that eschewstructured 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

[edit]

Inlogic 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 aredeclarative, focusing on what the problem is, rather than on how to solve it.

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

H :- B1, …, Bn.

have a dual interpretation, both as procedures

to show/solveH, show/solveB1 and … andBn

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

[edit]

References

[edit]
  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.IEEE.doi:10.1109/CAIA.1991.120848.S2CID 58175293.
  3. ^Stevenson, Joseph (August 2013)."Procedural programming vs object-oriented programming". neonbrand.com. Retrieved2013-08-19.

External links

[edit]
Imperative
Structured
Object-oriented
(comparison,list)
Declarative
Functional
(comparison)
Dataflow
Logic
Domain-
specific
language

(DSL)
Concurrent,
distributed,
parallel
Metaprogramming
Separation
of concerns
Level
Generation
Retrieved from "https://en.wikipedia.org/w/index.php?title=Procedural_programming&oldid=1313720013"
Category:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp