Hi,
Could anyone tell me the meaning of side effect in the following line:
If you're calling an EL function that doesn't return anything, then you're calling it just for its side effects.
many thanks in advance.
Hi,
Could anyone tell me the meaning of side effect in the following line:
If you're calling an EL function that doesn't return anything, then you're calling it just for its side effects.
many thanks in advance.
This means that you're not calling a "true" function, in the mathematical sense. Such a function always returns a value, which is totally decided by its input parameters. There is no "state" to modify, and nothing else can happen. This is why functional programming is interesting from the parallelization point of view; it makes it easier to prove that e.g. two function calls are independent and can run in parallel.
See the Wikipedia entry on pure functions for further detail.
A side effect is anything a method does besides computing and returning a value. Any change of instance or class field values is a side effect, as is drawing something on the screen, writing to a file or a network connection.
Strictly speaking, a "function" is defined as not having side effects - which is why Java uses the word "method" instead. A real function with no return value would be pointless.
Obviously, a method that does not have a return value must have some sort of side effect that justifies its existence. Set methods are an example - the side effect is changing the object's internal state.
A side effect is when a method call changes a class's state. So
public class SideEffectClass{
private int state = 0;
public doSomething(int arg0){
state += arg0;
}
}
Here, doSomething(int arg0) has the side effect of changing the state variable.
When you think of a program, you can think of it as instructions + state + input. So if the domain of a program is the range of all possible input * state, and the program has side effects, you can see that the codomain of possible results for the application can grow explosively, as the number of side effects increase. This makes the possible states for the program large, which leads to complicated testing. The functional programming paradigm is designed to eliminate side effects. By making functions first class citizens and by making all declarations immutable functional programming prevents side effects, which makes functional programming shine in parallel processing, as synchronization issues are reduced.