Side effect (computer science)
In computer science, an operation or expression is said to have a side effect if it has any observable effect other than its primary effect of reading the value of its arguments and returning a value to the invoker of the operation.[6] Example side effects include modifying a non-local variable, a static local variable or a mutable argument passed by reference; performing I/O; or calling other functions with side-effects.[6] In the presence of side effects, a program's behaviour may depend on history; that is, the order of evaluation matters.[6] Understanding and debugging a function with side effects requires knowledge about the context and its possible histories.[6] Side effects play an important role in the design and analysis of programming languages.[1] The degree to which side effects are used depends on the programming paradigm.[6] For example, imperative programming is commonly used to produce side effects, to update a system's state.[5] By contrast, declarative programming is commonly used to report on the state of system, without side effects.[6] Functional programming aims to minimize or eliminate side effects.[4] The lack of side effects makes it easier to do formal verification of a program.[6] The functional language Haskell eliminates side effects such as I/O and other stateful computations by replacing them with monadic actions.…[6]
In computer science, an operation or expression is said to have a side effect if it has any observable effect other than its primary effect of reading the value of its arguments and returning a value to the invoker of the operation.[6] Example side effects include modifying a non-local variable, a static local variable or a mutable argument passed by reference; performing I/O; or calling other functions with side-effects.[6] In the presence of side effects, a program's behaviour may depend on history; that is, the order of evaluation matters.[6] Understanding and debugging a function with side effects requires knowledge about the context and its possible histories.[6] Side effects play an important role in the design and analysis of programming languages.[1] The degree to which side effects are used depends on the programming paradigm.[6] For example, imperative programming is commonly used to produce side effects, to update a system's state.[5] By contrast, declarative programming is commonly used to report on the state of system, without side effects.[6] Functional programming aims to minimize or eliminate side effects.[4] The lack of side effects makes it easier to do formal verification of a program.[6] The functional language Haskell eliminates side effects such as I/O and other stateful computations by replacing them with monadic actions.[6] Functional languages such as Standard ML, Scheme and Scala do not restrict side effects, but it is customary for programmers to avoid them.[5] Effect systems extend types to keep track of effects, permitting concise notation for functions with effects, while maintaining information about the extent and nature of side effects.[6] In particular, functions without effects correspond to pure functions.[src] Assembly language programmers must be aware of hidden side effects—instructions that modify parts of the processor state which are not mentioned in the instruction's mnemonic.[6] A classic example of a hidden side effect is an arithmetic instruction that implicitly modifies condition codes (a hidden side effect) while it explicitly modifies a register (the intended effect).[6] One potential drawback of an instruction set with hidden side effects is that, if many instructions have side effects on a single piece of state, like condition codes, then the logic required to update that state sequentially may become a performance bottleneck.[6] The problem is particularly acute on some processors designed with pipelining (since 1990) or with out-of-order execution.[src] Such a processor may require additional control circuitry to detect hidden side effects and stall the pipeline if the next instruction depends on the results of those effects.[6] Side effects caused by the time taken for an operation to execute are usually ignored when discussing side effects and referential transparency.[6] There are some cases, such as with hardware timing or testing, where operations are inserted specifically for their temporal side effects e.g.[6] sleep(5000) or for (int i = 0; i .[src] These instructions do not change state other than taking an amount of time to complete.[src] x = 0 def setx(n): global x x = n setx(3) assert x == 3 setx(3) assert x == 3 setx is idempotent because the second call of setx to 3 has the same effect on the system state as the first call: x was already set to 3 after the first call, and it is still set to 3 after the second call.[6] A pure function is idempotent if it is idempotent in the mathematical sense.[src] For instance, consider the following Python program: def abs(n): return -n if n abs is idempotent because the second call of abs to the return value of the first call to -3 returns the same value as the first call to -3.[6] One common demonstration of side effect behavior is that of the assignment operator in C.[6] The assignment a = b is an expression that evaluates to the same value as the expression b , with the side effect of storing the R-value of b into the L-value of a .[6] This allows multiple assignment: a = (b = 3); // b = 3 evaluates to 3, which then gets assigned to a Because the operator right associates, this is equivalent to a = b = 3; This presents a potential hangup for novice programmers who may confuse while (b == 3) {} // tests if b evaluates to 3 with while (b = 3) {} // b = 3 evaluates to 3, which then casts to true so the loop is infinite[src]
40 sentences · 40 cited inline · 10 references stored
References
- CSc 520 Principles of Programming Languages · retrieved 2022-08-05 · rev 1355884722
Cite this reference
MLA "CSc 520 Principles of Programming Languages." Collberg, Christian S. 2022-08-05. https://web.archive.org/web/20220806155136/https://www2.cs.arizona.edu/~collberg/Teaching/520/2005/Html/Html-24/index.html. Accessed 25 November 2026.
Chicago "CSc 520 Principles of Programming Languages." Collberg, Christian S. 2022-08-05. https://web.archive.org/web/20220806155136/https://www2.cs.arizona.edu/~collberg/Teaching/520/2005/Html/Html-24/index.html.
APA Collberg, Christian S. (2022). CSc 520 Principles of Programming Languages. Retrieved November 25, 2026, from https://web.archive.org/web/20220806155136/https://www2.cs.arizona.edu/~collberg/Teaching/520/2005/Html/Html-24/index.html
- How To Design Programs · retrieved 2026-11-20 · rev 1355884722
Cite this reference
MLA "How To Design Programs." Felleisen, Matthias ; Findler, Robert Bruce; Flatt, Matthew; Krishnamurthi, Shriram (2014-08-01). 2026-11-20. https://en.wikipedia.org/wiki/Matthias_Felleisen. Accessed 25 November 2026.
Chicago "How To Design Programs." Felleisen, Matthias ; Findler, Robert Bruce; Flatt, Matthew; Krishnamurthi, Shriram (2014-08-01). 2026-11-20. https://en.wikipedia.org/wiki/Matthias_Felleisen.
APA Felleisen, Matthias ; Findler, Robert Bruce; Flatt, Matthew; Krishnamurthi, Shriram (2014-08-01). (2026). How To Design Programs. Retrieved November 25, 2026, from https://en.wikipedia.org/wiki/Matthias_Felleisen
- Haskell 98 report · retrieved 2026-11-20 · rev 1355884722
Cite this reference
MLA "Haskell 98 report." 2026-11-20. http://www.haskell.org. Accessed 25 November 2026.
Chicago "Haskell 98 report." 2026-11-20. http://www.haskell.org.
APA encyclopegia.org. (2026). Haskell 98 report. Retrieved November 25, 2026, from http://www.haskell.org
- Why Functional Programming Matters · retrieved 2022-08-05 · rev 1355884722
Cite this reference
MLA "Why Functional Programming Matters." Turner, David A. 2022-08-05. https://en.wikipedia.org/wiki/David_Turner_(computer_scientist). Accessed 25 November 2026.
Chicago "Why Functional Programming Matters." Turner, David A. 2022-08-05. https://en.wikipedia.org/wiki/David_Turner_(computer_scientist).
APA Turner, David A. (2022). Why Functional Programming Matters. Retrieved November 25, 2026, from https://en.wikipedia.org/wiki/David_Turner_(computer_scientist)
- Jones, Simon Peyton; Wadler, Phil (1993). Imperative Functional Programming . Conference Record of the 20th Annual ACM Symposium on Principles of Programming Languages. pp. 71– 84. Wikipedia revision 1355884722, retrieved 2026-11-21 · retrieved 2026-11-20 · rev 1355884722
Cite this reference
MLA "Jones, Simon Peyton; Wadler, Phil (1993). Imperative Functional Programming . Conference Record of the 20th Annual ACM Symposium on Principles of Programming Languages. pp. 71– 84. Wikipedia revision 1355884722, retrieved 2026-11-21." Jones, Simon Peyton; Wadler, Phil (1993). 2026-11-20. https://en.wikipedia.org/w/index.php?oldid=1355884722. Accessed 25 November 2026.
Chicago "Jones, Simon Peyton; Wadler, Phil (1993). Imperative Functional Programming . Conference Record of the 20th Annual ACM Symposium on Principles of Programming Languages. pp. 71– 84. Wikipedia revision 1355884722, retrieved 2026-11-21." Jones, Simon Peyton; Wadler, Phil (1993). 2026-11-20. https://en.wikipedia.org/w/index.php?oldid=1355884722.
APA Jones, Simon Peyton; Wadler, Phil (1993). (2026). Jones, Simon Peyton; Wadler, Phil (1993). Imperative Functional Programming . Conference Record of the 20th Annual ACM Symposium on Principles of Programming Languages. pp. 71– 84. Wikipedia revision 1355884722, retrieved 2026-11-21. Retrieved November 25, 2026, from https://en.wikipedia.org/w/index.php?oldid=1355884722
- Spuler, David A.; Sajeev, A. Sayed Muhammed (January 1994). Compiler Detection of Function Call Side Effects . James Cook University . CiteSeerX 10.1.1.70.2096 . The term Side effect refers to the modification of the nonlocal environment. Generally this happens when a function (or a procedure) modifies a global variable or arguments passed by reference parameters. But here are other ways in which the nonlocal environment can be modified. We consider the following causes of side effects through a function call: 1. Performing I/O. 2. Modifying global variables. 3. Modifying local permanent variables (like static variables in C). 4. Modifying an argument passed by reference. 5. Modifying a local variable, either automatic or static, of a function higher up in the function call sequence (usually via a pointer). {{ cite book }} : Cite uses deprecated parameter |citeseerx= ( help ) Wikipedia revision 1355884722, retrieved 2026-11-21 · retrieved 2026-11-20 · rev 1355884722
Cite this reference
MLA "Spuler, David A.; Sajeev, A. Sayed Muhammed (January 1994). Compiler Detection of Function Call Side Effects . James Cook University . CiteSeerX 10.1.1.70.2096 . The term Side effect refers to the modification of the nonlocal environment. Generally this happens when a function (or a procedure) modifies a global variable or arguments passed by reference parameters. But here are other ways in which the nonlocal environment can be modified. We consider the following causes of side effects through a function call: 1. Performing I/O. 2. Modifying global variables. 3. Modifying local permanent variables (like static variables in C). 4. Modifying an argument passed by reference. 5. Modifying a local variable, either automatic or static, of a function higher up in the function call sequence (usually via a pointer). {{ cite book }} : Cite uses deprecated parameter |citeseerx= ( help ) Wikipedia revision 1355884722, retrieved 2026-11-21." Spuler, David A. 2026-11-20. https://en.wikipedia.org/wiki/James_Cook_University. Accessed 25 November 2026.
Chicago "Spuler, David A.; Sajeev, A. Sayed Muhammed (January 1994). Compiler Detection of Function Call Side Effects . James Cook University . CiteSeerX 10.1.1.70.2096 . The term Side effect refers to the modification of the nonlocal environment. Generally this happens when a function (or a procedure) modifies a global variable or arguments passed by reference parameters. But here are other ways in which the nonlocal environment can be modified. We consider the following causes of side effects through a function call: 1. Performing I/O. 2. Modifying global variables. 3. Modifying local permanent variables (like static variables in C). 4. Modifying an argument passed by reference. 5. Modifying a local variable, either automatic or static, of a function higher up in the function call sequence (usually via a pointer). {{ cite book }} : Cite uses deprecated parameter |citeseerx= ( help ) Wikipedia revision 1355884722, retrieved 2026-11-21." Spuler, David A. 2026-11-20. https://en.wikipedia.org/wiki/James_Cook_University.
APA Spuler, David A. (2026). Spuler, David A.; Sajeev, A. Sayed Muhammed (January 1994). Compiler Detection of Function Call Side Effects . James Cook University . CiteSeerX 10.1.1.70.2096 . The term Side effect refers to the modification of the nonlocal environment. Generally this happens when a function (or a procedure) modifies a global variable or arguments passed by reference parameters. But here are other ways in which the nonlocal environment can be modified. We consider the following causes of side effects through a function call: 1. Performing I/O. 2. Modifying global variables. 3. Modifying local permanent variables (like static variables in C). 4. Modifying an argument passed by reference. 5. Modifying a local variable, either automatic or static, of a function higher up in the function call sequence (usually via a pointer). {{ cite book }} : Cite uses deprecated parameter |citeseerx= ( help ) Wikipedia revision 1355884722, retrieved 2026-11-21. Retrieved November 25, 2026, from https://en.wikipedia.org/wiki/James_Cook_University
- Research Topics in Functional Programming . Addison-Wesley . 1990. · retrieved 2026-05-23 · rev 1355884722
Cite this reference
MLA "Research Topics in Functional Programming . Addison-Wesley . 1990." Research Topics in Functional Programming. 2026-05-23. https://en.wikipedia.org/w/index.php?oldid=1355884722. Accessed 25 November 2026.
Chicago "Research Topics in Functional Programming . Addison-Wesley . 1990." Research Topics in Functional Programming. 2026-05-23. https://en.wikipedia.org/w/index.php?oldid=1355884722.
APA Research Topics in Functional Programming. (2026). Research Topics in Functional Programming . Addison-Wesley . 1990. Retrieved November 25, 2026, from https://en.wikipedia.org/w/index.php?oldid=1355884722
- CSc 520 Principles of Programming Languages . Department of Computer Science, University of Arizona . 2005-04-22. · retrieved 2026-05-23 · rev 1355884722
Cite this reference
MLA "CSc 520 Principles of Programming Languages . Department of Computer Science, University of Arizona . 2005-04-22." CSc 520 Principles of Programming Languages. 2026-05-23. https://en.wikipedia.org/w/index.php?oldid=1355884722. Accessed 25 November 2026.
Chicago "CSc 520 Principles of Programming Languages . Department of Computer Science, University of Arizona . 2005-04-22." CSc 520 Principles of Programming Languages. 2026-05-23. https://en.wikipedia.org/w/index.php?oldid=1355884722.
APA CSc 520 Principles of Programming Languages. (2026). CSc 520 Principles of Programming Languages . Department of Computer Science, University of Arizona . 2005-04-22. Retrieved November 25, 2026, from https://en.wikipedia.org/w/index.php?oldid=1355884722
- htdp.org . · retrieved 2026-05-23 · rev 1355884722
Cite this reference
MLA "htdp.org ." htdp. 2026-05-23. https://en.wikipedia.org/w/index.php?oldid=1355884722. Accessed 25 November 2026.
Chicago "htdp.org ." htdp. 2026-05-23. https://en.wikipedia.org/w/index.php?oldid=1355884722.
APA htdp. (2026). htdp.org . Retrieved November 25, 2026, from https://en.wikipedia.org/w/index.php?oldid=1355884722
- Haskell 98 report . 1998. · retrieved 2026-05-23 · rev 1355884722
Cite this reference
MLA "Haskell 98 report . 1998." Haskell 98 report. 2026-05-23. https://en.wikipedia.org/w/index.php?oldid=1355884722. Accessed 25 November 2026.
Chicago "Haskell 98 report . 1998." Haskell 98 report. 2026-05-23. https://en.wikipedia.org/w/index.php?oldid=1355884722.
APA Haskell 98 report. (2026). Haskell 98 report . 1998. Retrieved November 25, 2026, from https://en.wikipedia.org/w/index.php?oldid=1355884722
Cite this article
MLA
"Side effect (computer science)." encyclopegia.org, 2026, https://encyclopegia.org/wiki/side-effect-computer-science. Accessed 25 November 2026.
Chicago
"Side effect (computer science)." encyclopegia.org. Accessed November 25, 2026. https://encyclopegia.org/wiki/side-effect-computer-science.
APA
encyclopegia.org. (2026). Side effect (computer science). Retrieved November 25, 2026, from https://encyclopegia.org/wiki/side-effect-computer-science
Accessed November 25, 2026 · CC BY-SA 4.0 · citation page · JSON