I don't understand the definition of side effects
Posted
by
Chris Okyen
on Programmers
See other posts from Programmers
or by Chris Okyen
Published on 2012-09-01T19:49:53Z
Indexed on
2012/09/01
21:48 UTC
Read the original article
Hit count: 291
state
|side-effect
I don't understand the wikipedia article on Side Effects:
In computer science, a function or expression is said to have a side effect if, in addition to returning a value, it also 1.) Modifies some state or 2.) Has an observable interaction with calling functions or the outside world.
I know an example of the first thing that causes a function or expression to have side effects - modifying a state
Function and Expression modifying a state :
1.)
foo(int X)
{
return x = x % x;
}
a = a + 1;
What does 2.) - Has an observable interaction with calling functions or the outside world," mean? - Please give an example.
The article continues on to say, "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...." Are all these examples, examples of 1.) - Modifiying some state , or are they also part of 2.) - Has an observable interaction with calling functions or the outside world?
© Programmers or respective owner