Procedure (programming)

from Wikipedia, the free encyclopedia

Procedure is a term used in the programming of computer systems . In general, this is understood as a variant of the term “ subroutine ”: The instructions of a procedure can be called by their name and thus used multiple times .

Terminology and details differ

Depending on the programming language and programming paradigm, there are differences in the definition of the term procedure and how it is differentiated from the term function .

FORTRAN77 example, acting under procedures functions and procedural subroutines ( subroutines together). In the terminology of the C standard, every subroutine is a function, regardless of whether a value is returned. In object-oriented programming , both concepts are often summarized under the collective term method .

In contrast to a function (which delivers exactly one return value as a direct result) , a procedure only supplies its results indirectly (via internal variables or via reference parameters in the calling program).

In general, a procedure can have call parameters and can also change the values ​​of variables or store results there, for example a response code. A distinction is made here between local (only valid within the procedure and cannot be influenced from the outside) and global (declared outside of the procedure) variables. Changing global variables within a procedure can impair the clarity of the program and make troubleshooting more difficult.

Procedures such as functions can also be compiled in program libraries depending on the language . This makes it possible to call up a procedure from separate program modules or from other programs .

Deviating meanings: In COBOL , procedures are only the instructions (commands) formulated in the 'Procedure Division', which can be named by 'Paragraphs', regardless of whether they are used as a subroutine or not. In PL / I , too, the instructions contained in the command part of the source text - which are to be processed procedurally (= 'progressively') - are referred to as “procedures”.

Examples

The following examples each define a procedure for drawing a line with a number of points.

Pascal

In the Pascal programming language , which uses procedures explicitly as a language element, a procedure, unlike a function, by definition does not return a value:

Example of a procedure in Pascal :

procedure PunkteZeichnen(anzahl: Integer);
var
    i: Integer;
begin
    for i := 1 to anzahl do
        Write('.');
end;

Example of a procedure call in Pascal:

PunkteZeichnen(5);

BASIC

Realization of a procedure in a modern BASIC variant (subroutine without return value):

public sub PunkteZeichnen(anzahl as Integer)
    for i as Integer = 1 to anzahl
        Debug.print(".")
    next i
end sub

Example of a method call in Basic:

call PunkteZeichnen(5)

C.

Implementation of a procedure in C . The keyword voidspecifies that the function does not provide a return value:

void punkte_zeichnen(int anzahl) {
    for (int i = 0; i < anzahl; ++i)
        putchar('.');
}

Example of a function call in C:

punkte_zeichnen(5);

Java

Realization of a procedure in Java (method without return value):

public class Beispiel {
    public static void punkteZeichnen(int anzahl) {
        for (int i = 0; i < anzahl; ++i)
            System.out.print (".");
    }
}

Example of a method call in Java:

  punkteZeichnen(5);

Individual evidence

  1. FORTRAN77 standard, chap. 15. fortran.com, accessed September 20, 2010 .
  2. C99 standard. (PDF; 3.8 MB) open-std.org, accessed on September 12, 2010 (English, non-normative working document).
  3. Procedures-Functions-Methods. (PDF; 309 kB) uni-frankfurt.de, accessed on December 1, 2015 .
  4. Procedural abstraction, functions. uni-koeln.de, accessed on September 20, 2010 .