Side effect (computer science)

In theoretical computer science effect refers to the change of the state in which there is an abstract machine. Examples include the change of contents of the memory. Effects in this sense are also called side-effect. Sometimes it is also spoken by a side effect, a designation which goes back to an incorrect back-translation of the English side effect.

  • 3.1 Documents on the definition of "effect"
  • 3.2 Documents to use the term "effect"

Linguistic aspects

The terms " side effect ", " side effect" or " side effect" is misleading because it's not about the demarcation against any "main" effect. Therefore, the word to prefer "effect".

Specified effects

A variable represents a specific value at any time during program execution. The totality of all variables and their values ​​defines the program state of an abstract machine (see operational semantics ). Operations with specified effects can change it.

To differentiate from these, the specified effect unspecified effects that are outside the contemplation of the system. Purpose, for example, depending on the definition, the screen output are. These effects are not considered, if applicable for the abstract machine.

Programming languages

In most programming languages ​​, the evaluation of an expression have a specified effect. Expressions and functions can either effectively vitiated or reactively. The group of functions with effect all who have to do with the input or output of data includes, for example, in the rule. Effect -free functions in high-level languages ​​are about mathematical functions such as sine, cosine, or square root.

Absence of reaction in the purely functional programming

In purely functional languages ​​, the evaluation of an expression, in contrast to other programming languages ​​never a specified effect. There are no instructions in such languages ​​, but only expressions. It does not use any variables and values ​​assignments. To produce an effect of outputting a result is not a specified action in this case. In the purely functional programming therefore occur no state changes in the sense of the above definition and therefore no effects. The programming language is stateless and reactively.

This property of a programming language is called referential transparency. It says that the value of an expression depends only on its environment and not from the point in time or a particular order of evaluation. Examples of fully -effect-free languages ​​are purely functional programming languages ​​Haskell or pure Lisp ( pure Lisp ).

In other functional programming languages ​​such as Scheme procedure calls can modify the values ​​of variables or trigger screen output. The referential transparency is lost and Scheme is therefore not a pure functional language. To highlight this property in the used for educational purposes Language Scheme, afflicted with effects procedures are marked with an exclamation point, for example, in the variable assignment ( set! a 2).

Example

The following typical with its brackets and prefix notation for a language like Lisp or Scheme example program delivers dependent back of a condition one of two possible calculation results.

( if ( = a 0)    ( A 1)    (* A 2) ) The assignment of the result to a variable does not occur. In particular, but the order of evaluation of each function has (if, =, , and *) no influence on the result. Each expression can be replaced at any point by its value. This is the referential transparency.

Documents for terms and statements

Evidence on the definition of " effect "

The meaning of the term " action " in the computer science generally agrees with the importance of this word in everyday language match (where you tacitly always thinks only a specified action). In everyday language, the effects of an operation are indeed the caused by this change, ie its consequences. Any definitions in the literature of computer science give it back just sometimes something formal or just restricted to relevant special cases. Often the term is also used without explicit definition, if the meaning of the word is meant, which it has in everyday life.

  • "If ZP is thus the set of all possible states that can (formally be traversed during the execution of the program P: ZP ⊂ W ( v ₁) × W ( v ₂) × ... × W ( vn ), where v ₁, ..., vn the occurring in P variables and W ( vi) the range of values ​​of vi, ie the set of all values ​​that vi can assume are ), then the effect of a statement a ∈ P is a mapping F [ a]: ZP → ZP, the one state z ∈ ZP a successor state z ' ∈ ZP assigns. Example: Let V = { x, y} and P = "..., x ≔ y 1; ... '. If before reaching the allocation of state z = ( x = ⊥, y = 5) applies, after the statement is true, the state z ' = ( x = 6, y = 5). Formal: F [ x ≔ y 1] (⊥, 5) = (6, 5) ".

Evidence on the use of the term "effect"

  • Have "Description of the action, the instructions on states ( = variable assignments ). [...] Then the effect of the instruction m: = n 1 as follows [...]. "
  • " For each operation the following information must be provided: [ ... ] a description of the effect of the operation ."
  • Even in the English literature of computer science, the term "effect" is often used ( side effect engl. effect, so do not about only "side effect", engl. ). For example, one finds in the standard of C applications such as: "the effect of dereferencing the null pointer" ( " The effect of dereferencing the null pointer "). The term is used to describe the effect of instructions, as in " A return statement in main Has the effect of leaving the main function" ( " A return statement in main has the effect of leaving the main function "). He is explicitly defined in one place for functions: " Effects: the actions Performed by the function" ( " effect: the actions performed by the function "). Then in the description of each function is a section with " Effects " ( " effects " ) labeled, indicating the effects of the function described, as in " atexit ... Effects: The atexit () functions register the function pointed to by f .... " ( " atexit ... effects: the function atexit () registers the function pointed to the f .... ").
721552
de