Saturday, August 13, 2011

Stateful and Stateless Condition Checks

if(cond1 && cond2)
{
object.setState(true);
}

is not the same as:

object.setState(cond1 && cond2);

The second block sets the state of the object to true if both "cond1" and "cond2" are true, else it sets state to false. Either way, the state of the object is altered and the previous state is lost.

The first block sets the state of the object to true if both "cond1" and "cond2" are true, else IT DOES NOTHING. The state of the object is not altered otherwise.

There is a small difference, and it hurts.

PS: Why did I share this? Just so you know. As Senthil says, "Inpormason .. is .. wealth"

2 Comments:

Anonymous Anonymous said...

Very interesting points. Thanks!

My blog:
dsl anbieter www.dslvergleichdsl.com

1:26 AM  
Blogger " Mad "ness said...

good one!

1:42 PM  

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home