Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Side effect--what's this?

Tags:

java

jsp

People also ask

What's side effect mean?

Definition of side effect : a secondary and usually adverse effect (as of a drug) toxic side effects. — called also side reaction.

What is the effect of side effect?

Side effects, also known as adverse reactions, are unwanted undesirable effects that are possibly related to a drug. Side effects can vary from minor problems like a runny nose to life-threatening events, such as a heart attack or liver damage.

What is a side effect give an example?

Side effects: Problems that occur when treatment goes beyond the desired effect. Or problems that occur in addition to the desired therapeutic effect. Example -- A hemorrhage from the use of too much anticoagulant (such as heparin) is a side effect caused by treatment going beyond the desired effect.

What causes side effect?

Why do side effects occur? Side effects occur because the body is a very complex. It is difficult to make a drug that targets one part of the body but that doesn't affect other parts. Developing drugs is also complicated because no two people are exactly the same.


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.


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 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.


When you use a medicine, it's side effects are those that are generally unwanted bad effects. The main purpose to use it is to get it's "demanded" effect. Here, when we look at the angle of functions, generally when you call them you get a calculated value and use. There are other functions that they also change some values while calculating the "demanded" value so here the "changing some values" is a side effect. In the description of your sentence, if a function does not return anything, it is only used for its side effects so here, the side effects are "changing some values".