wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Side effects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Side effects" Watch "Side effects" New topic
Author

Side effects

Java Daisuki
Greenhorn

Joined: Jul 30, 2005
Posts: 6
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Joined: Oct 02, 2003
Posts: 11169
    
  16

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



There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
wood burning stoves
 
subject: Side effects
 
Similar Threads
What did you get from 2007 .
nunit
if (x != null) vs in (null != x)
execute script in background with ANT
what is the difference between servlet config&servletContext