Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Side effects

 
Java Daisuki
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone. I really appreciate of gaining access to this site and everyone's contributions. I am a REAL beginner with No IT, computing background starting learning Java 3 mths ago.

Please anyone explain to me in plain English, what is the side effects ? My book said that if a method modifies some outside value other than its implicit parameters, we call that modification a side effect.

What is the difference between implicit parameter and explicit parameter ?

Thank you.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First the business side

"Java" -

I am assuming that Java is not your real first name.

Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok let's assume this code



Basically a side effect is where you are changing some value that is not scoped directly to just the method, but outside the method and you change some value to something outside the method. Therefore any other method, class, or variable cannot assume that that value outside the method scope is going to be the same, there is a side effect and it can cause problems outside the method.

Say you call some other method and it still expects that that instanceVariable.mySideEffectVariable is still equal to 10, not knowing that the changeOutsideValue method changed it to 20, and therefore that other method returns an incorrect value that what is expected.

Hope that helps.

Mark
 
fred rosenberger
lowercase baba
Bartender
Posts: 12125
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i've alse seen the term used in relation to the short circuit boolean operators. say you have code like this

strange things can happen. sometime the i variable will be incremented, and sometimes not, depending on the value of myVar.

if you want i incremented, it should be outside of the if-condition entirely...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic