(en.wikipedia.org) Side effect (computer science) - Wikipedia

ROAM_REFS: https://en.wikipedia.org/wiki/Side_effect_(computer_science)

In computer science, an operation, function 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. Example side effects include modifying a non-local variable, a static local variable or a mutable argument passed by reference; raising errors or exceptions; performing I/O; or calling other functions with side-effects. In the presence of side effects, a program's behaviour may depend on history; that is, the order of evaluation matters. Understanding and debugging a function with side effects requires knowledge about the context and its possible histories. Side effects play an important role in the design and analysis of programming languages. The degree to which side effects are used depends on the programming paradigm. For example, imperative programming is commonly used to produce side effects, to update a system's state. By contrast, declarative programming is commonly used to report on the state of system, without side effects.

Functional programming aims to minimize or eliminate side effects. The lack of side effects makes it easier to do formal verification of a program. The functional language Haskell eliminates side effects such as I/O and other stateful computations by replacing them with monadic actions. Functional languages such as Standard ML, Scheme and Scala do not restrict side effects, but it is customary for programmers to avoid them.

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. In particular, functions without effects correspond to pure functions.

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. 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). 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. The problem is particularly acute on some processors designed with pipelining (since 1990) or with out-of-order execution. 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.

Local Graph

org-roam 2a07e4ea-610b-4c9a-bb84-d961fb2450e5 Code and Coffee Book Club 49444189-1d98-43b7-b64c-2c31466c4734 (en.wikipedia.org) Side effect (compu... 2a07e4ea-610b-4c9a-bb84-d961fb2450e5->49444189-1d98-43b7-b64c-2c31466c4734 //en.wikipedia.org/wiki/Computer_science https://en.wikipedia.org/wiki/Computer_science 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Computer_science //en.wikipedia.org/wiki/Subroutine https://en.wikipedia.org/wiki/Subroutine 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Subroutine //en.wikipedia.org/wiki/Expression_(programming) https://en.wikipedia.org/wiki/Expression_(programming) 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Expression_(programming) //en.wikipedia.org/wiki/Non-local_variable https://en.wikipedia.org/wiki/Non-local_variable 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Non-local_variable //en.wikipedia.org/wiki/Static_local_variable https://en.wikipedia.org/wiki/Static_local_variable 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Static_local_variable //en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference //en.wikipedia.org/wiki/I/O https://en.wikipedia.org/wiki/I/O 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/I/O //en.wikipedia.org/wiki/Programming_language https://en.wikipedia.org/wiki/Programming_language 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Programming_language //en.wikipedia.org/wiki/Imperative_programming https://en.wikipedia.org/wiki/Imperative_programming 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Imperative_programming //en.wikipedia.org/wiki/Declarative_programming https://en.wikipedia.org/wiki/Declarative_programming 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Declarative_programming //en.wikipedia.org/wiki/Functional_programming https://en.wikipedia.org/wiki/Functional_programming 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Functional_programming //en.wikipedia.org/wiki/Formal_verification https://en.wikipedia.org/wiki/Formal_verification 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Formal_verification //en.wikipedia.org/wiki/Haskell_(programming_language) https://en.wikipedia.org/wiki/Haskell_(programming_language) 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Haskell_(programming_language) //en.wikipedia.org/wiki/Input/output https://en.wikipedia.org/wiki/Input/output 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Input/output //en.wikipedia.org/wiki/Monad_(functional_programming) https://en.wikipedia.org/wiki/Monad_(functional_programming) 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Monad_(functional_programming) //en.wikipedia.org/wiki/Standard_ML https://en.wikipedia.org/wiki/Standard_ML 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Standard_ML //en.wikipedia.org/wiki/Scheme_(programming_language) https://en.wikipedia.org/wiki/Scheme_(programming_language) 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Scheme_(programming_language) //en.wikipedia.org/wiki/Scala_(programming_language) https://en.wikipedia.org/wiki/Scala_(programming_language) 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Scala_(programming_language) //en.wikipedia.org/wiki/Effect_system https://en.wikipedia.org/wiki/Effect_system 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Effect_system //en.wikipedia.org/wiki/Assembly_language https://en.wikipedia.org/wiki/Assembly_language 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Assembly_language //en.wikipedia.org/wiki/Status_register https://en.wikipedia.org/wiki/Status_register 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Status_register //en.wikipedia.org/wiki/Processor_register https://en.wikipedia.org/wiki/Processor_register 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Processor_register //en.wikipedia.org/wiki/Instruction_set https://en.wikipedia.org/wiki/Instruction_set 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Instruction_set //en.wikipedia.org/wiki/Instruction_pipeline https://en.wikipedia.org/wiki/Instruction_pipeline 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Instruction_pipeline //en.wikipedia.org/wiki/Out-of-order_execution https://en.wikipedia.org/wiki/Out-of-order_execution 49444189-1d98-43b7-b64c-2c31466c4734->//en.wikipedia.org/wiki/Out-of-order_execution