All Topics  
Procedural programming

 

   Email Print
   Bookmark   Link






 

Procedural programming



 
 
Procedural programming can sometimes be used as a synonym for imperative programming
Imperative programming

In computer science, imperative programming is a programming paradigm that describes computation in terms of statement s that change a program state ....
 (specifying the steps the program must take to reach the desired state), but can also refer (as in this article) to a programming paradigm
Programming paradigm

A programming paradigm is a fundamental style of computer programming. . Paradigms differ in the concepts and abstractions used to represent the elements of a program and the steps that compose a computation ....
 based upon the concept of the procedure call. Procedures, also known as routines, subroutine
Subroutine

In computer science, a subroutine or subprogram is a portion of computer code within a larger computer program, which performs a specific task and is relatively independent of the remaining code....
s, methods, or functions (not to be confused with mathematical functions, but similar to those used in functional programming
Functional programming

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of function s and avoids program state and immutable object data....
) simply contain a series of computational steps to be carried out.






Discussion
Ask a question about 'Procedural programming'
Start a new discussion about 'Procedural programming'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Procedural programming can sometimes be used as a synonym for imperative programming
Imperative programming

In computer science, imperative programming is a programming paradigm that describes computation in terms of statement s that change a program state ....
 (specifying the steps the program must take to reach the desired state), but can also refer (as in this article) to a programming paradigm
Programming paradigm

A programming paradigm is a fundamental style of computer programming. . Paradigms differ in the concepts and abstractions used to represent the elements of a program and the steps that compose a computation ....
 based upon the concept of the procedure call. Procedures, also known as routines, subroutine
Subroutine

In computer science, a subroutine or subprogram is a portion of computer code within a larger computer program, which performs a specific task and is relatively independent of the remaining code....
s, methods, or functions (not to be confused with mathematical functions, but similar to those used in functional programming
Functional programming

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of function s and avoids program state and immutable object data....
) 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. A procedural programming language provides a programmer a means to define precisely each step in the performance of a task. The programmer knows what is to be accomplished and provides through the language step-by-step instructions on how the task is to be done. Using a procedural language, the programmer specifies language statements to perform a sequence of algorithmic steps. 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
    GOTO

    GOTO is a statement found in many computer programming languages. It is a combination of the English words wiktionary:go and wiktionary:to....
    " or "JUMP" statements (which can turn a large, complicated program into spaghetti code
    Spaghetti code

    Spaghetti code is a pejorative term for source code which has a complex and tangled control structure, especially one using many GOTOs, exceptions, threads, or other "unstructured" Branch constructs....
    ).
  • The ability to be strongly modular or structured
    Structured programming

    Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO Statement ....
    .


Some good examples of procedural programs are the Linux Kernel, GIT, Apache Server, and Quake III Arena.

Procedures and modularity


Modularity
Modularity (programming)

Modular programming is a software design technique that increases the extent to which software is composed from separate parts, called modules. Conceptually, modules represent a separation of concerns, and improve maintainability by enforcing logical boundaries between components....
 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.

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 variable
Variable

A variable is a symbol that stands for a value that may vary; the term usually occurs in opposition to constant, which is a symbol for a non-varying value, i.e....
s 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 and Software package
Software package (programming)

A software package is used in object-oriented programming to name a group of related class es of a program. Packages are useful to measure and control the inherent coupling of a program....
.)

Comparison with imperative programming


Most procedural programming languages are also imperative
Imperative programming

In computer science, imperative programming is a programming paradigm that describes computation in terms of statement s that change a program state ....
 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
Processor register

In computer architecture, a processor register is a small amount of Computer storage available on the CPU whose contents can be accessed more quickly than storage available elsewhere....
s) to something like the position of the "turtle" in the Logo programming language.

Comparison with object-oriented programming


The focus of procedural programming is to break down a programming task into a collection of variables, data structures, and subroutines, whereas in object-oriented programming
Object-oriented programming

Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs....
 it is to break down a programming task into object
Object (computer science)

In its simplest embodiment, an object is an allocated region of storage. Since programming languages use variable#Computer_programmings to access objects, the terms object and variable are often used interchangeably....
s. Either method can be valid for accomplishing a specific programming task.

Some differences between pure object-oriented languages and non-OO procedural languages:

object-orientedprocedural
methods functions
objects modules
message argument
attribute variable


Comparison with logic programming


In logic programming
Logic programming

Logic programming is, in its broadest sense, the use of mathematical logic for computer programming. In this view of logic programming, which can be traced at least as far back as John McCarthy 's [1958] Advice taker proposal, logic is used as a purely Declarative programming language representation language, and a automated theorem proving o...
, 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
Declarative

Declarative may refer to:*Declarative programming*Declarative learning*Declarative memory*Declarative notation a method of defining variables in computer programming...
, focusing on what the problem is, rather than on how to solve it.

However, the backward reasoning technique, implemented by SLD resolution
SLD resolution

SLD resolution is the basic inference rule used in logic programming. It is a refinement of Resolution , which is both sound and refutation complete for Horn clauses....
, used to solve problems in logic programming languages such as Prolog
Prolog

Prolog is a logic programming language. It is a general purpose language often associated with artificial intelligence and computational linguistics....
, 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.


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.

See also


  • Functional programming
    Functional programming

    In computer science, functional programming is a programming paradigm that treats computation as the evaluation of function s and avoids program state and immutable object data....
     (contrast)
  • Imperative programming
    Imperative programming

    In computer science, imperative programming is a programming paradigm that describes computation in terms of statement s that change a program state ....
  • Logic programming
    Logic programming

    Logic programming is, in its broadest sense, the use of mathematical logic for computer programming. In this view of logic programming, which can be traced at least as far back as John McCarthy 's [1958] Advice taker proposal, logic is used as a purely Declarative programming language representation language, and a automated theorem proving o...
  • Object-oriented programming
    Object-oriented programming

    Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs....
  • Programming paradigm
    Programming paradigm

    A programming paradigm is a fundamental style of computer programming. . Paradigms differ in the concepts and abstractions used to represent the elements of a program and the steps that compose a computation ....
    s
  • Programming language
    Programming language

    A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
  • Procedural generation
    Procedural generation

    Procedural generation is a widely used term in the production of media, indicating the possibility to create content on the fly rather than prior to distribution....
     (contrast)
  • Structured programming
    Structured programming

    Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO Statement ....


External links