• (cs) in reply to Oli

    new Array(
     true,
     false,
     OR_ELSE
    );

  • Justin. (unregistered) in reply to RevMike
    RevMike:


    Us SQL developers know this should really be
    enum Bool 
    {
    True,
    False,
    NULL
    };



    You beat me to it. 

    Absolutely - there is nothing wrong with tertiary logic: true, false and unknown.  A few moments thought for the C programmers out there should enable you to work out the logical and pattern in tertiary logic.  Here's the logical or for example:

    V| T F ?
    --------
    T| T T T
    F| T F ?
    ?| T ? ?

    Cheers,
    Justin.
  • javascript jan (unregistered) in reply to robbak
    Anonymous:
    dubwai:

    I don't think people are seeing the value in this.

    In standard logic, the statement "all deep-sea dwelling elephants can fly" is true.  With this addition, the answer is now FileNotFound; a much more satisfying answer.



    Incorrect. The statment is undefined.


    We have a phrase for this: "clearly not a logician". I suppose you don't believe that the empty set exists, either?
  • anonymouse (unregistered) in reply to rikkus

    That would be because return status of 0 is success... And return status' have more than 2 possibilities.

  • (cs) in reply to anonymouse
    Anonymous:
    rikkus:
    Anonymous:

    The more subtle WTF is that, by default, True is 0 and False is 1.  Which is completely bass-ackwards.

    UNIX would beg to differ:


    > [ -d / ]; echo $?
    0
    > [ -f / ]; echo $?
    1
    That would be because return status of 0 is success... And return status' have more than 2 possibilities.


    This took me a few moments to put together.  It makes sense inside a command shell.
  • (cs) in reply to anonymouse

    @Eric: I see what you mean. I can't think of a better name for that either - maybe EditableState or something, but I don't think that's better. It's a minor WTF, since it's pretty obvious what's going on.

    OTOH, the OP was a real WTF, since he was calling it "Bool", which may or may not have anything to do with files.

    Now, someone said that it may be on Unix where most things are represented by files, but I'm not sure if, say, a checkbox is represented by a file or not. It would seem incredibly strange to have something like

    checkbox1.Checked = Bool.FileNotFound;

    A boolean value, by definition, can only ever be true or false. Now, before anyone shouts about nulls, they are used when there is NO value at all. A boolean shows whether something is true or false, and you'd use null instead to show that there is no data either way, or maybe that the question doesn't apply in that situation. By the same token, a null int isn't actually a number - it's an indication that there is no numbber to use in that situation.

  • (cs) in reply to johnl
    johnl:
    A boolean value, by definition, can only ever be true or false. Now, before anyone shouts about nulls, they are used when there is NO value at all. A boolean shows whether something is true or false, and you'd use null instead to show that there is no data either way, or maybe that the question doesn't apply in that situation. By the same token, a null int isn't actually a number - it's an indication that there is no numbber to use in that situation.


    Remember that most of us are doing programming, not mathematical research.  Our programs generally model something.  The fact that the mathematical concept of Boolean does not include a third Unknown/NA state does not make that construct any less valid within our programs.  If you need to be rigorous, just model your pragmatic booleans as two boolean attributes: the boolean value and a null/not null indicator value.  In fact, this is precisely the technique that SQL<->procedural language bridges like Pro*C use to indicate a null value in a host language primitive type.
  • (cs) in reply to Justin.
    Justin:


    V| T F ?
    --------
    T| T T T
    F| T F ?
    ?| T ? ?



    I think it makes a lot more sense this way:

    W| T F ?

    --------

    T| T T T

    F| T F ?

    ?| T ? ?

  • (cs) in reply to RevMike

    I was trying to point out that a third option in the form of NULL is useful, though I'd rather simply have true or false, then set it to null if needed:

    bool fileOpen; //can only be true or false

    if(!FileExists('something.txt')) { fileOpen = null; //not storing a value }

    It's a personal preference. It would be acceptable for bool to allow a third option explicitly, rather than using the built-in null value like (that's available for all/most datatypes) I have used here. However, for other things, such as shown in the OP, calling it BOOL is confusing because people will try to use it in situations where the third option simply doesn't make any sense. In that situation, you really do need to call it something else.

  • Pete (unregistered)

    Do a quick search on "ternary" or "trinary" and wake up to the way the world will go one fine day! and There is trinary logic and it kinda works in java already as you can have true, false and un-initalised!

  • (cs) in reply to Pete

    Once more for the hard of reading:

    For other things, such as shown in the OP, calling it BOOL is confusing because people will try to use it in situations where the third option simply doesn't make any sense. In that situation, you really do need to call it something else.

    "uninitialised" is really analagous to "null" - the value can either be true or false but you haven't set it yet, so it's neither. Perhaps a little more specific, but certainly not on the same lines as FileNotFound.

    Besides, the only thing I can find on "ternary" in Java is the ternary operator that you get in C++ (test ? true : false), which is actually still binary logic - the "ternary" part of the name refers to thefact that it takes 3 operands.

    Some people have written Ternary classes (such as http://www.cs.princeton.edu/introcs/60circuits/Ternary.java.html), though these aren't standard AFAIK. And the people who have done that haven't been stupid enough to call their work "boolean" have they?

  • Mike (unregistered)

    Digital Electronics guru's know that there is, of course: true (1), false (0) and don't care (X).

  • (cs) in reply to stevekj
    stevekj:
    Justin:


    V| T F ?
    --------
    T| T T T
    F| T F ?
    ?| T ? ?



    I think it makes a lot more sense this way:

    W| T F ?

    --------

    T| T T T

    F| T F ?

    ?| T ? ?



    Yes, your way makes quite a difference.

    ok
    dpm

  • smudge (unregistered) in reply to johnl

    No - you have missed the point here. Remember the Y2K bug - no one thought that their software would last until the year 2000?

    He is merely catering for the advent of the tri-state bit in the quantum computer.

    It can be true, false or in an indeterminate state. In this case, FileNotFound is the indeterminate state.

    It can also be expressed thus:

    public enum cat
    {
       alive;
       dead;
       noIdea;
    }

    Of course, once you know the result, then it's determinate. So it can never be noIdea. You with me?

    Smudge

    PS. Do you think that sometimes Schrodinger opened his lunch box and his sandwiches were there, and sometimes, they weren't?

  • (cs) in reply to smudge

    Not sure if you were responding to me. Either way I couldn't work out everything you were saying - what exactly does the Y2K bug have to do with it?

    "Of course, once you know the result, then it's determinate. So it can never be noIdea. You with me?"

    So if I understand correctly, this is exactly what I was saying. In your example, there's no issue beause you've not used the word bool.

    The problem isn't that he had a third state (though there's a perfectly valid case that this should be achieved by other means), but that he had a third state called FileNotFound. Now, that's fine if you're dealing specifically with files, but in this case we're not, we're dealing with redefining a widely-used datatype. That's fine too, as long as you cater for the fact that it will be used in lots of situations.

    The problem is that elsewhere in the program we might re-use this enum in a context where FileNotFound is a nonsensical value. That's an easy mistake to make because there's nothing about this enum to suggest it's specific to files. If there was, it would be a strange coding practice, rather than a serious WTF.

    I'm personally of the opinion that bools should still only have two states, and the bool itself should be null when there's no data. If that's not possible, then don't call it a bool. Would you do something like this:

    string databaseConnectionString = "I like monkeys";

  • Kelmi (unregistered) in reply to RevMike
    RevMike:

    The fact that the mathematical concept of Boolean does not include a third Unknown/NA state does not make that construct any less valid within our programs.



    The mathematical concept of Boolean algebras does NOT limit the number of elements.

  • (cs) in reply to johnl
    johnl:
    string databaseConnectionString = "I like monkeys";


    I'd really like to know how you figured out my company's connection string.  PM me if necessary.
  • smudge (unregistered) in reply to Ytram

    johnl - that was a bit of a tongue in cheek reply on my part. I agree with you though.

    In any case, defining something with the same name as a primitive is a bad idea. If it needs redefining, it needs a new name.

    This is just wrong - we all know that because we can code (albeit in my case, badly...) ;-)

  • (cs) in reply to smudge

    Ah, right. I wasn't sure.

    "In any case, defining something with the same name as a primitive is a bad idea. If it needs redefining, it needs a new name."

    Yeah, you're probably right.

    YTram, I can't just give away all my l337 h4xx0r trade secrets, now can I? ;)

  • (cs) in reply to uh oh.
    Anonymous:

    so shouldn't we replace booleans with a 3 dimesional float vector?

     1) trueness : -1.0f =completely false, 1.0f =completely true

    2) reliability: -1.0f=not at all sure about axis 1, 1.0f=absolutely confident

    3) how much i #$%ing care: -1.0f= i don't care at all, 1.0f = it really matters to me

     



    You sorta already have a "datatype" you could use for this... RGB 00-FF:00-FF;00-FF.

    So, what does a dark mauve mean to you?
  • (cs) in reply to RevMike
    RevMike:
    Anonymous:
    Whose turn is it to explain why this isn't all that bad after-all?


    I'll give it a shot...

    The programmer was enumerating the return types of a function or method whose job was to inspect a file.  The program in question has some property named Bool which is set true or false depending on some aspect of some file.  The getBool function/method attempts to examine the file and return the proper Bool state,  The return types could reasonably be true, false, and file not found.

    Now, the choice of the name Bool was unfortunate, but they are really checking for the something having to do with a Pool.  They used the word Bool instead of Pool because B and P sort-of  look alike, and they prefer their Pool to not have P in it.


    I also prefer my Pool to not have P in it.  That would be... unsanitary.
  • (cs) in reply to Pete
    Anonymous:
    There is trinary logic and it kinda works in java already as you can have true, false and un-initalised!


    Not in Java. There is a compiler warning you can get when using an possibly uninitialized local variable, but there is no such thing as an uninitialized variable at runtime - the compiler forces you to initialize local variables, and member variables are automatically initialized to null, 0 or false.
  • Niels (unregistered) in reply to kipthegreat
    kipthegreat:

    I've always favored calling a trinary digit a tit.


    Bits good, tits better? And how would the relation of bytes and nibbles to tits be?

    <ponders>
  • (cs) in reply to Kaizer

    Kaizer:
    Oh.. yah, my bad... I meant 'deep-sea' not 'deep-see'...

    But seriously, we are trying to evaluate wether a statement is true or not.  If there are no deep-sea dwelling elephants (which is getting annoying to type) than the statement should automatically be false.

    Nope.  It's called a vacous truth.

    http://en.wikipedia.org/wiki/Vacuous_truth

  • (cs) in reply to brazzy
    brazzy:
    Anonymous:
    There is trinary logic and it kinda works in java already as you can have true, false and un-initalised!


    Not in Java. There is a compiler warning you can get when using an possibly uninitialized local variable, but there is no such thing as an uninitialized variable at runtime - the compiler forces you to initialize local variables, and member variables are automatically initialized to null, 0 or false.

    And a Boolean object can't be inicializated as undefined. Either it holds true or it holds false. If it is null then there is no Boolean object at all.

    You can of course overload the meaning of not having a Boolean object as not being sure of the condition it represents:

    public void doSomething ( Boolean hasMoney ) { if ( hasMoney == null ) { //we don't know if he has money // check pockets for money } else if ( hasMoney.booleanValue() ) { //take money away } else { //we're sure he/she has no money // insult him/her for not having money so you can mug him } }

  • (cs) in reply to Enric Naval

    "Bits good, tits better? And how would the relation of bytes and nibbles to tits be?"

    Like tits, but bigger? I think we should let this line of conversation stop there...

  • (cs) in reply to dubwai
    dubwai:

    Kaizer:
    Oh.. yah, my bad... I meant 'deep-sea' not 'deep-see'...

    But seriously, we are trying to evaluate wether a statement is true or not.  If there are no deep-sea dwelling elephants (which is getting annoying to type) than the statement should automatically be false.

    Nope.  It's called a vacous truth.

    http://en.wikipedia.org/wiki/Vacuous_truth

    What's with you people and your damn elephants?

    From wikipedia:

    "All elephants inside a loaf of bread are pink.  is vacuously true since there are no elephants inside a loaf of bread"

     

  • tim (unregistered) in reply to kipthegreat

    This works in C#.

  • (cs)

    Truth is beauty [H]

  • (cs) in reply to robbak
    Anonymous:
    dubwai:

    I don't think people are seeing the value in this.

    In standard logic, the statement "all deep-sea dwelling elephants can fly" is true.  With this addition, the answer is now FileNotFound; a much more satisfying answer.



    Incorrect. The statment is undefined.


    Incorrect. This corresponds to the predicate logic formula "ForAll(x): (IsElephant(x) and IsDeepSeaDwelling(x)) implies CanFly(x)". In the model of the real world, "IsElephant(x) and IsDeepSeaDwelling(x)" is false for all x, thus the implication is always true. q.e.d.

  • (cs) in reply to Kaizer
    Kaizer:

    But seriously, we are trying to evaluate wether a statement is true or not.  If there are no deep-sea dwelling elephants (which is getting annoying to type) than the statement should automatically be false.



    Making implications evaluate to false if the prerequisite is not met would be a seriously nonsensical thing to do.

    The formula you've given ("All deep-sea dwelling elephants can fly, and there exists at least one deep-sea dwelling elephant") is not equivalent to dubwai's example.

  • (cs) in reply to Otac0n
    Otac0n:

    and...

    3 tits would be a tybble

    3 tytes would be a tyurd

    3 tyurds would be a long tyurd



    Shouldn't the equivalent of a nibble be a nipple?

  • MillSoft (unregistered)

    S = { True, False, FindBetterAxioms }

  • (cs) in reply to emptyset
    emptyset:

    christoofar:
    The problem with opponents of basic modal logic, of course, is that proponents of ulterior transmogrified logic systems must use modal logic to base their preposterous arguments… arguments which appear to resemble something, when consumed, tastes entirely unlike tea.

    <font face="Courier New" size="2">i would like to transmogrify into a tiger.</font>



    How Hobbesian
  • (cs) in reply to kipthegreat

    kipthegreat:
    Anonymous:
    This is clearly forward-thinking code.  A tri-state bool is what you would expect to find on a trinary-based architecture.  If a bit (trit?) equals 2, perhaps that means FileNotFound.  Some of us are still not ready for this mind blowing scenario where each bit can be true, false, or 404nf, but this code is clearly ready to be ported to these computers if and when they are created.  How many of you can claim to have written code with such portability in mind?


    I've always favored calling a trinary digit a tit.

    If half a Byte is a nibble, would half a tit be a nipple?

  • (cs) in reply to uh oh.
    Anonymous:

    in which case 9 tits would be tyte

    And it would operate under Boleyn logic...

  • (cs) in reply to Gene Wirchenko
    Gene Wirchenko:
    Mung Kee:
    RevMike:
    Us SQL developers know this should really be
    enum Bool 
    {
    True,
    False,
    NULL
    };

    We developers...




    Not to be completely pedantic but....

    enum Bool
    {
        True, 
        False,
        NULL,

       Nothing
    };

  • (cs) in reply to bigb

    bigb:
    Truth is beauty [H]

    Truth is Beauty; Beauty Truth.  But if I get out of this one alive, I'll never eat meat again.

    (Nick Danger - Third Eye)

  • (cs) in reply to Bustaz Kool

    Let S = {All sets s such that s is not an element of s}

    If S is an element of S ==> S is not an element of S

    If S is not an element of S ==> S is not an element of S

    (Bertrand Russell Paradox)

  • phx (unregistered) in reply to Bustaz Kool

    public bool? foo;

    foo = false;

    foo = true;

    foo = null;

    C# 2.0 ;)

  • php programmer (unregistered) in reply to phx
    Anonymous:

    public bool? foo;

    foo = false;

    foo = true;

    foo = null;

    C# 2.0 ;)



    You must be kidding - that works in C#?  Are they using objects behind the scenes for their bool primatives?  What is the memory footprint of a boolean primative in C# then, or does it cast null to false as it is assigned to an actual primate bool?  Is (false == null) true?


    As far as people mentioning that if that was an unfortunate name for the enum - would anyone really turn a bool response into an enumeration with secondary error flags? 

    Personally, I think that is where you would want to use a FileNotFound exception, and be smart enough to check for the file before the function call to get the true/false response.

    IMHO  If you return a value that is 'true' and another that is 'false' no matter how you cut it, !false should always be true and !true should always be false, otherwise you need "if (response != true && response != false) getMysteryPrize(); " since some guy could have added to the returned enum without you knowing, and "(!true && !false) == true" should always be a WTF.

    About the flying sea elephants:

    I think what is said, is if "all the elephants under the sea can fly" and you ask  "are there any elephants under the sea that can't fly?" you have to respond "there are no elephants that can't fly under the sea."  If there are no elephants under the sea that can't fly, then can't they all fly down there?   They all can pass the test, all zero of them.  Of course "all the elephants under the sea can't fly" is also true, so it is not a statement of actual boolean logic (any more than filenotfound)

    Its more a demonstration how truth/false tests are limited and can't answer all questions in a useful way, only some.  Take "True of false:  You enjoyed stealing the money." as an example:  Yes or No only make any sense if you did steal the money. 
    Just like "bool doesTheFileHaveNeatStuffInIt(File f)" only makes sense if there is a file to check.  The answer isn't to provide more response options in addition to true/false, but not to ask for a single true/false response when the condition's result relies on another condition being true that hasn't been tested.

    I can't wait to see this one though for a get milisec function:

    enum Long
    {
    0,
    1,
    <snip>
    1000000000000,
    1000000000001,
    <snip>
    (2^64),
    DateNotFound
    };





  • php programmer (unregistered) in reply to php programmer
    me:

    enum Long
    {
    0,
    1,
    <snip>
    1000000000000,
    1000000000001,
    <snip>
    (2^64),
    DateNotFound
    }</snip></snip>



    meant that to say

    enum Long
    {
    0,
    1,
    ...snip...<snip>
    1000000000000,
    1000000000001,</snip>
    ...snip...<snip><snip> (2^64),
    DateNotFound
    }</snip></snip>
    ...but I used gt/lt chars and they didn't show
  • goober foober (unregistered) in reply to php programmer
    Anonymous:
    Anonymous:

    public bool? foo;

    foo = false;

    foo = true;

    foo = null;

    C# 2.0 ;)



    You must be kidding - that works in C#? 
    snip...

    You just fell for a troll because bool? is C# compiler sugar for declaring a Nullable<bool>, which is a struct, and is not the primitive type bool (no question mark).

  • (cs) in reply to Hexar

    Anonymous:
    <FONT face=Verdana size=1>The more subtle WTF is that, by default, True is 0 and False is 1.  Which is completely bass-ackwards.</FONT>

    It doesn't matter what True and False are in terms of bit values as long as they're used consistently throughout the code. Don't think that True "should be" 1 and False "should be" 0; True could be 3921 and False could be 2005. It really doesn't matter.

    As for the "FileNotFound"... I think the programmer is actually quite clever to come up with such a construct. The practicality of this is not evident at first - but if you think about it, it's a good way to propagate the condition across the entire program via returning it through various functions. However he could've cleaned it up a little by eliminating False and renaming True to Success. Then it is easy to see that one can incorporate various other error conditions in there too -

    AccessDenied

    FileInUse

    PathNotFound

    ReadError

    WriteError

    ...

  • (cs) in reply to javascript jan

    Anonymous:
    We have a phrase for this: "clearly not a logician". I suppose you don't believe that the empty set exists, either?

    <FONT face="Courier New" size=2>i post, therefore i am.</FONT>

  • (cs) in reply to JohnO
    JohnO:

    RevMike:

    You haven't heard of the new database called "Us SQL"?  :)  Its pretty cool.  It uses advanced regex technology to be fully text searchable in O(1).

    That's caching, BTW.[8-|]

    <FONT face="Courier New" size=2>you said it, mon.</FONT>

  • (cs) in reply to Kaizer

    Kaizer:
    "All elephants inside a loaf of bread are pink.  is vacuously true since there are no elephants inside a loaf of bread"

    <FONT face="Courier New" size=2>in my country, elephant burgers are amazing delicacies.</FONT>

  • phx (unregistered) in reply to goober foober
    Anonymous:
    Anonymous:
    Anonymous:

    public bool? foo;

    foo = false;

    foo = true;

    foo = null;

    C# 2.0 ;)



    You must be kidding - that works in C#? 
    snip...

    You just fell for a troll because bool? is C# compiler sugar for declaring a Nullable<BOOL>, which is a struct, and is not the primitive type bool (no question mark).

    Troll?

    Its bloody tasty sugar, makes dealing with databases that little bit easier.

  • (cs) in reply to ???

    Yes, sure, I think he has his own enum of Ints  :)

  • v0idnull (unregistered) in reply to johnl

    if (true)
    {
        return 1;
    } elseif (false) {
        return 0;
    } else {
        return 0.5;
    }

Leave a comment on “What Is Truth?”

Log In or post as a guest

Replying to comment #:

« Return to Article