Share on Facebook Share on Twitter Email
Answers.com

side effect

 

n.
A peripheral or secondary effect, especially an undesirable secondary effect of a drug or therapy.


Search unanswered questions...
Enter a question here...
Search: All sources Community Q&A Reference topics
Mosby's Dental Dictionary:

side effect

Top

n

An effect not sought in the case under treatment.

Random House Word Menu:

categories related to 'side effect'

Top
Random House Word Menu by Stephen Glazier
For a list of words related to side effect, see:

  See crossword solutions for the clue Side-effect.
Wikipedia on Answers.com:

Side effect (computer science)

Top

In computer science, a function or expression is said to have a side effect if, in addition to returning a value, it also modifies some state or has an observable interaction with calling functions or the outside world. For example, a function might modify a global or static variable, modify one of its arguments, raise an exception, write data to a display or file, read data, or call other side-effecting functions. In the presence of side effects, a program's behavior depends on history; that is, the order of evaluation matters. Understanding a program with side effects requires knowledge about the context and its possible histories; and is therefore hard to read, understand and debug.[1][2]

Side effects are the most common way to enable a program to interact with the outside world (people, filesystems, other computers on networks). But the degree to which side effects are used depends on the programming paradigm. Imperative programming is known for its frequent utilization of side effects. In functional programming, side effects are rarely used. Functional languages such as Standard ML and Scheme do not restrict side effects, but it is customary for programmers to avoid them.[3] The functional language Haskell restricts side effects with a static type system; it uses the concept of monads to do stateful and IO computations.[4][5]

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 which explicitly modifies a register (an overt effect) and implicitly modifies condition codes (a hidden side effect). One defect of an instruction set with many hidden side effects is that if many instructions all 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 processors designed with instruction pipeline (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.

Contents

Referential transparency

Absence of side effects is necessary but not sufficient for referential transparency. Referential transparency means that an expression (such as a function call) can be replaced with its value; this requires that the expression has no side effects and is pure (always returns the same results on the same input).

Temporal side effects

Side effects due to the time taken for an operation to execute are usually ignored when discussing side effects and referential transparency. In most programs it is desirable to replace a long operation with an equivalent shorter one e.g. replacing (60 / 3 * 2) with 40. There are some cases, such as with hardware timing or testing, where operations are inserted specifically for their temporal side effects e.g. Sleep(5000) or for(i=0; i < 10000; i++){}. These instructions do not change state other than taking an amount of time to complete.

Idempotence

A side effect free function f is always idempotent (under sequential composition f ; f, not function composition ff).

Example

One common demonstration of side effect behavior is that of the assignment operator in C++. For example, the assignment operator returns the value getting assigned and has the side effect of assigning that value to a variable. This allows for syntactically clean multiple assignment:

int i, j;
i = j = 3;

Because the C++ assignment operator right associates, this is equivalent to

int i, j;
i = (j = 3); //j = 3 returns 3, which then gets assigned to i

Where the result of assigning 3 into "j" is then assigned into "i". This is a potential hangup for novice programmers who are apt to confuse

while (i == true) {}; //Tests if i evaluates to true

with

while (i = true) {}; //The result of the assignment function is "true", so the loop conditional always evaluates to true


See also

References

  1. ^ “Research Topics in Functional Programming” ed. D. Turner, Addison-Wesley, 1990, pp 17–42. Retrieved from: Hughes, John (PDF), Why Functional Programming Matters, http://www.cs.utexas.edu/~shmat/courses/cs345/whyfp.pdf 
  2. ^ Collberg, CSc 520 Principles of Programming Languages, Department of Computer Science, University of Arizona, http://www.cs.arizona.edu/~collberg/Teaching/520/2005/Html/Html-24/index.html 
  3. ^ Matthias Felleisen et al., How To Design Programs, MIT Press
  4. ^ Haskell 98 report, http://www.haskell.org.
  5. ^ Imperative Functional Programming, Simon Peyton Jones and Phil Wadler, Conference Record of the 20th Annual ACM Symposium on Principles of Programming Languages, pages 71–84, 1993

 
 

 

Copyrights:

American Heritage Dictionary. The American Heritage® Dictionary of the English Language, Fourth Edition Copyright © 2007, 2000 by Houghton Mifflin Company. Updated in 2009. Published by Houghton Mifflin Company. All rights reserved.  Read more
Mosby's Dental Dictionary. Mosby's Dental Dictionary. Copyright © 2004 by Elsevier, Inc. All rights reserved.  Read more
Random House Word Menu. © 2010 Write Brothers Inc. Word Menu is a registered trademark of the Estate of Stephen Glazier. Write Brothers Inc. All rights reserved.  Read more
Bradford's Crossword Solver's Dictionary. Collins Bradford's Crossword Solver's Dictionary © Anne Bradford, 1986, 1993, 1997, 2000, 2003, 2005, 2008 HarperCollins Publishers All rights reserved.  Read more
Wikipedia on Answers.com. This article is licensed under the Creative Commons Attribution/Share-Alike License. It uses material from the Wikipedia article Side effect (computer science) Read more

Follow us
Facebook Twitter
YouTube