boolean has three values!!!


Heres the code snippet I just found in our code base. They guy coded this up as boolean can have values other than true and false or may be this code is future ready when booleans really get three valued.

public void doSomething( boolean verify ) {
if (verify) {
 // do something
} else if (!verify( {
 // do some other thing
} else {
 // do something wierd
}

Note: I am not posting the exact code snippet because of copyright issues and other legal mumbo jumbo you all are aware of.

Advertisements
boolean has three values!!!

7 thoughts on “boolean has three values!!!

  1. Hmmm, I wonder if this was something that was refactored? Ie, maybe it originally took a Boolean, instead of a boolean and the third case dealt with the case where the object was == null?

  2. Just playing a devil’s advocate here but since this is not the original code, could it be that boolean is actually Boolean, in which case, it does take a third possible value I.E. null

  3. nano says:

    Boolean is the distinct definition as to how we live and by we program. In life there are only two things, true or false. NULL is 0 and 0 is false. The else statement is a programed conditional thats incorporated into the c/c++ structure, not logic. The compiler would disregard that condition by not compiling it to avoid bloated code.

  4. I’m not sure what language the sample is in, but when I use C# a boolean can only ever be true or false. Not zero, not null. That’s the way it should be — completely unambiguous. You cannot pass a type that does not translate into exactly “true” or “false” as a boolean parameter.

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