Programming pearl of the day (not)

Extract from live production code…


boolean flag = false;
boolean and = false;
boolean or = false;
....
public void and(){
   and = true;
   or = false;
}

....

public void or() {
   and = false;
   or = true;
}

“and” and “or” are not reserved keywords in Java so they can be used as variable names. Is this a good idea though ? The answer a few lines below:



if ( or || (and || flag ) || (!and && !or) ){
   //some logic here
}
else
if (and || (!and && !or)){
   //more logic here

}

I’ll leave you to decide if it’s genius or madness. Although there’s probably a lesson to be learn somewhere about the importance of good variables names.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s