• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Side effects

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic