Overheard in the next cube



  • I overheard two developers talking in the next cubicle this morning.

    Dev #1: So it's a logical value, right?
    Dev #2: Yes, a boolean value.
    Dev #1: Then it's true, false or unassigned.
    Dev #2: Right.

    The next sound was me slapping my forehead.






  • Maybe Java?

    Dev #1: Then it's true, false or unassigned.

    They could have been talking about the Java class Boolean. A Boolean instance can have three values: TRUE, FALSE and null. Very useful in artificial intelligence or other domains where trinary logic is a must.



  • @flicken said:

    Dev #1: Then it's true, false or unassigned. They could have been talking about the Java class Boolean. A Boolean instance can have three values: TRUE, FALSE and null. Very useful in artificial intelligence or other domains where trinary logic is a must.

     

    There is NO WAY in wich a Boolean value will have thre posibilities, because it's used strictly in two-value logic, I will agree with you and the guys in the other cubicle if they where talking about a logic value or even better a tri-state value. But I will also have to admit that I have no special problem with people that refers to tri-state values as boolean, I usually bypass that in order to continue the conversation, but...  I also have to admit that I hate all of them when they write specifications in which they say that some variable will be true or false (and thus I assign it to boolean) and later I find out that it can be also null.

    The key thing is that you are forgiving them for saying that is a bool while you say it correctly and cite the datatype as trinary logic. Let's keep boolean logic for bi-state logic and whatever name we want for more than 2 values logic.



  • Well that depends I think wether its a local variable or an instance variable. At least if my memory doesn't fail to serve me.

    Local variables aren't initialized on declaration, but is unassigned a value?



  • Without knowing the language involved, it's hard to tell, but if the OP is doing a head-slap, then I'm thinking this isn't Java.  In C or C++, a boolean is either true or false.  It might be true because it wasn't initialized and is exporting bit junk (and it might also be false, but not as often), but it'll still be either true or false. 

    Debug builds might initialize it, even.  (To false, I expect, because underneath it's probably an int.)

     



  • They could just have been working with SQL or other similar system where booleans can be NULL. This is not a WTF without more context.



  • @zamies said:

    Well that depends I think wether its a local
    variable or an instance variable. At least if my memory doesn't fail to
    serve me.

    Local variables aren't initialized on declaration, but is unassigned a value?




    If it's a java.lang.Boolean, then like all reference variables, it's
    initialized to null. If it's a boolean primitive, it's initialized to
    false, and there is no "unassigned" state, only true and false.



    This is for class and instance variables. If you don't initialize a
    local variable before using it, the compiler will reject the code.



    Another area where booleans have an "unassigned" state would be DBs.



  • Boolean is a construct in a language, in some cases it can be null, NULL, whatever.
    Binary is the term used to describe a system in which there are only two values, which is what you were thinking of.



  • That boolena could have been a C++ BOOL. At least in windows that is usually typedefed as an int. That BOOL can have the values TRUE (1), FALSE (0) or any other value which is unassigned (even though it evaluates to true).



  • Um, there is no type BOOL in C++.  There's just bool, which is a type (not a typedef), which has the values true or false.

    You may be thinking of BOOL, which is a typedef in Win32.  But that's a proprietary C API, nothing to do with C++.



  • This has come up before here, and I still don't understand the confusion.  A boolean value can be true or false.  That's all.

    If it's a Boolean (in Java), then it can be true or false.  The reference to the Boolean might be null, but in that case, it's not a valid reference to a Boolean.

    If it's SQL, a boolean still only has two values, true or false.  Null is not a boolean value, any more than null is a string value.  A null indicates the complete lack of a value.  It's unknown/missing/whatever.  Null is not a boolean value, anymore than it's an integer value.

    The PostgreSQL documentation agrees with this:
    boolean can have one of only two states: "true" or "false". A third state, "unknown", is represented by the <acronym style="font-style: italic;" class="ACRONYM">SQL</acronym> null value.



  • "Null is not a boolean value, any more than null is a string value." <- Agh.  I deleted that line.  Sorry for the repitition.  Looks like the forum software bit me.



  • *repetition



  • It's been a while since I touched Java myself, but just checking...

    Boolean myBool = new Boolean();

    what's the value of myBool now? (is that even valid code?)



  • There is no default constructor for Boolean, so it's a compiler error.



  • I think it might have been a "long bool": {no, perhaps, maybe, probably, yes}



  • Well, I spent ages debugging a PHP script a while ago. (No PHP is not my usual language :) )


    I found that if using a variable that wasn't defined,


    if($undefed_var == TRUE)

      { // Never gets here... }

    else if($undefed_var == FALSE)

      { // Never gets here either... }

    else

      { // We end up here! }


    You don't know how long this took me to work out, since the reason the
    variable had not been defined was because of a typo in its name :)



  • @MattJ said:

    Well, I spent ages debugging a PHP script a while ago. (No PHP is not my usual language :) )


    I found that if using a variable that wasn't defined,


    if($undefed_var == TRUE)

      { // Never gets here... }

    else if($undefed_var == FALSE)

      { // Never gets here either... }

    else

      { // We end up here! }


    You don't know how long this took me to work out, since the reason the
    variable had not been defined was because of a typo in its name :)




    That happened because you were unfamiliar with the language. Every seasoned PHPer knows that



    error_reporting(E_ALL);



    is your friend. Don't ask. The WTF-ness of most PHP options is material for a whole category of threads...



Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.