• The Nerve (unregistered)

    Triple-negative logic FTW!

  • Morrell (unregistered)

    oh dear god

    my answer is Maybe

  • Alargule (unregistered)

    ^^ That is not not not not not not !=true=false

  • Gram ma (unregistered)
    Steven:
    FIRST

    fail.

  • TheRealWTF (unregistered)

    The Real WTF is that Alex totally missed out FILE_NOT_FOUND.

  • Cbuttius (cs)

    More importantly do we skip validation if fileNotFound occurs?

  • SR (unregistered)
    if (comment.compareTo (Comment.FRIST)) {
       return Boolean.FILE_NOT_FOUND;
    }
    

    Or something

  • BenHead (unregistered)

    What if it's NULL??

    Ok, even if the code is not a WTF, that one can be tough, especially if you work in more than one language.

  • Morrell (unregistered) in reply to BenHead

    tri-state boolean... now that's nuts :)

  • Crabs (unregistered)

    After some deliberation, this sets we do not skip validation if the status is not valid.

    Someone kill this person. Someone. I'd do it but I don't know the location.

  • Sigh (unregistered)

    Great, another Java moron that doesn't know how to code. Nothing to see here. Move along.

    And yes, once again for the second time in 3 days, TRWTF is Java.

  • Robert (unregistered) in reply to TheRealWTF
    TheRealWTF:
    The Real WTF is that Alex totally missed out FILE_NOT_FOUND.

    and what about XOR

  • Ah yes (unregistered)

    The best part about the code is it will be easy to add the conditionals for less than and greater than as well.

  • AR (unregistered) in reply to Robert

    NOT

  • Jakob H. Poulsen (unregistered)

    Jeebus, how does one arrive at that, rather than: skipValidation = !statusIsNotValid;

    I fully understand and accept the validity of the following for legibility: if (statusIsNotValid) skipValidation = false;

    ... but E.H.'s colleague should have his programming privileges revoked for messing with people's head like that! There's still a 50% chance that my code above does the opposite of his.

  • Cbuttius (cs) in reply to The Nerve

    I wouldn't be able to answer the question because I don't know what is the significance of compareTo returning 0. Does that show equality or inequality?

    With compare functions, 0 often means equality, with negative and positive results indicating < and >.

    Why in C if you want to test two strings for equality you might check !strcmp( str1, str2 ), although you might write that as strcmp( str1, str2 ) != 0.

    Here we are doing compare to False so it is either equal or it isn't, there is no less/greater option here.

    That we are checking statusNotValid is a necessity that statusValid does not exist as a variable, nor should it if statusNotValid exists and always has the opposite value.

    Similarly skipValidation has been set as the variable name and not validate.

    statusNotValid is an object? It must be because we are calling .compareTo() on it....

    Oh well, C++ is so much simpler sometimes with operator overloading.

  • brazzy (cs) in reply to Sigh
    Sigh:
    Great, another Java moron that doesn't know how to code. Nothing to see here. Move along.

    And yes, once again for the second time in 3 days, TRWTF is Java.

    Because using any language other than Java makes people magically unable to code crap...

    If you think Java is the problem here, TRWTF is you.

  • bertram (cs) in reply to Morrell
    Morrell:
    tri-state boolean... now that's nuts :)

    You must be new here ;)

  • Steve The Cynic (cs)

    This code is why E.H. has to have a desk in his workplace...

    To bounce his colleague's head off of, duh.

  • caffeine (unregistered)

    I was a bit disappointed when I opened today's WTF and it was so short.

    After reading it, though, this is a perfect entry in my opinion. Nothing fancy, and fits the 'worse than failure' mould perfectly. The code works and is valid (accidental pun) but so very very wrong.

  • bertram (cs) in reply to Sigh
    Sigh:
    Great, another Java moron that doesn't know how to code. Nothing to see here. Move along.

    And yes, once again for the second time in 3 days, TRWTF is Java.

    There is absolutely nothing about that code snippet that guarantees that it's Java. But thanks for playing.

  • Someone who can't be bothered to login from work (unregistered)

    At a basic level you could just have NAND and NOR, because they're functionally complete.

  • Someone You Know (cs)
    Alex Papadimoulis:
    At the most basic level, there's simply TRUE and FALSE with AND, OR, and NOT.

    Just to be pedantic: since either AND or OR can be constructed using just the other one and NOT, if you have both AND and OR, you're not at "the most basic level".

  • frits (cs)

    This is only a WTF if statusIsNotValid is a boolean. If it is some other type, this really isn't much of a WTF.

  • monkeyPushButton (unregistered) in reply to TheRealWTF
    Comment held for moderation.
  • Cbuttius (cs) in reply to Jakob H. Poulsen
    Jakob H. Poulsen:
    Jeebus, how does one arrive at that, rather than: skipValidation = !statusIsNotValid;

    I fully understand and accept the validity of the following for legibility: if (statusIsNotValid) skipValidation = false;

    ... but E.H.'s colleague should have his programming privileges revoked for messing with people's head like that! There's still a 50% chance that my code above does the opposite of his.

    1. If the condition does not occur, skipValidation is NOT assigned to true, it retains the value it had earlier. So we can't restructure to skipValidation = (some predicate). We could do skipValidation &&= predicate though.

    2. compareTo is a class method, and you can't just put if round your object. This isn't C++ with operator overloading.

  • highphilosopher (unregistered) in reply to Jakob H. Poulsen
    Comment held for moderation.
  • da Doctah (cs) in reply to Someone You Know
    Someone You Know:
    Alex Papadimoulis:
    At the most basic level, there's simply TRUE and FALSE with AND, OR, and NOT.

    Just to be pedantic: since either AND or OR can be constructed using just the other one and NOT, if you have both AND and OR, you're not at "the most basic level".

    When I took Logic Design, they showed us how to implement all three, along with any other Boolean function, using nothing but NAND gates throughout.

  • Matt K (unregistered) in reply to frits
    frits:
    This is only a WTF if statusIsNotValid is a boolean. If it is some other type, this really isn't much of a WTF.

    Troll or idiot?

  • Cbuttius (cs) in reply to bertram
    bertram:
    Sigh:
    Great, another Java moron that doesn't know how to code. Nothing to see here. Move along.

    And yes, once again for the second time in 3 days, TRWTF is Java.

    There is absolutely nothing about that code snippet that guarantees that it's Java. But thanks for playing.

    Boolean.FALSE is defined in Java.

  • Drew (unregistered) in reply to Cbuttius
    Cbuttius:
    We could do skipValidation &&= predicate though.

    What language has that operator?

  • Sigh (unregistered) in reply to bertram
    bertram:
    Sigh:
    Great, another Java moron that doesn't know how to code. Nothing to see here. Move along.

    And yes, once again for the second time in 3 days, TRWTF is Java.

    There is absolutely nothing about that code snippet that guarantees that it's Java. But thanks for playing.

    I know Java crap when I see it. You must not. First clue is Boolean.FALSE. That's the constant replacement for the Boolean type false. He used the Object reference rather than the primitive because the method compareTo (implements the Comparable interface) takes an object. Camel-case is the preferred standard for variable naming, which they got right.

    If you don't believe any of these statements, I refer you to Google.

  • Darth Boolean (unregistered)

    I have validated your logic! Pray I don't validate it any further.

  • Gozer Gozerian (unregistered) in reply to bertram
    bertram:
    Morrell:
    tri-state boolean... now that's nuts :)

    You must be new here ;)

    That's right Morrell, a tri-state boolean is actually considered minimum among professionals. Also a four and five-state booleans are sometimes used. Only six and above ones can be a bit nuts. ;)

  • Drew (unregistered) in reply to Sigh
    Sigh:
    Great, another Java moron that doesn't know how to code. Nothing to see here. Move along.

    And yes, once again for the second time in 3 days, TRWTF is Java.

    Are you implying that only Java developers write bad code? Are you implying that it is impossible to write good code with Java? Are you implying that anyone who writes in Java writes bad code?

    Or are you making comments off the cuff before you've had your coffee this morning? :)

  • Jakob H. Poulsen (unregistered) in reply to Cbuttius
    1. Point well taken.

    2. Ever since Java 5 we have auto(un)boxing. The original code could be older than that though.

  • frits (cs) in reply to Matt K
    Matt K:
    frits:
    This is only a WTF if statusIsNotValid is a boolean. If it is some other type, this really isn't much of a WTF.

    Troll or idiot?

    The answer to your question is yes. ;)

    If statusIsNotValid is some other type, one could implement compareTo to return 0 for Boolean.FALSE if some special condition exists. This would be a little strange, but could be documented elsewhere. Based on this one line of code there isn't enough information about statusIsNotValid to definitively say this is as convoluted as most of you are assuming it is. Remember, assumption is the mother of all f*** ups.

  • Matt (unregistered)

    I can't not misunderstand what he was not trying to unachieve.

  • Sigh (unregistered) in reply to Drew
    Drew:
    Sigh:
    Great, another Java moron that doesn't know how to code. Nothing to see here. Move along.

    And yes, once again for the second time in 3 days, TRWTF is Java.

    Are you implying that only Java developers write bad code? Are you implying that it is impossible to write good code with Java? Are you implying that anyone who writes in Java writes bad code?

    Or are you making comments off the cuff before you've had your coffee this morning? :)

    I'm not sure whether it's because the language attracts idiots or because it's simple enough that it's easy to get your foot in the door. Unfortunately that is my hell now when all the C/C++ jobs went the way of the dinosaur. I see WAY more incompetent coders than I used to see in the C world. Of course, I can't complain about week-long #define hunts anymore.

  • Most Pessimum (unregistered) in reply to Jakob H. Poulsen
    Jakob H. Poulsen:
    E.H.'s colleague should have his programming privileges revoked for messing with people's head like that!
    QFT... In Programming 101 they taught us to always use "positive names" for boolean variables, i.e. statusValid and doValidation, as opposed to statusIsNotValid and skipValidation. Mostly because it avoids writing a complete and utter abortion of code, like what we see here.
  • vulputate (unregistered) in reply to Matt
    Matt:
    I can't not misunderstand what he was not trying to unachieve.
    +1, or actually -(-(-(-(1))))
  • Rootbeer (cs)

    I would hope that a function using a naming convention like 'fooIsBar' would return a boolean value, or at least something that can be reliably cast to boolean.

    Sometimes code is hopeless, though.

  • DonaldK (unregistered) in reply to Matt
    Matt:
    I can't not misunderstand what he was not trying to unachieve.

    Let's break it down:

    can't not = CAN ... I CAN misunderstand what he was not trying to unachieve.

    CAN misunderstand = misunderstand = do not understand ... I do not understand what he was not trying to unachieve.

    not trying to unachieve = trying to achieve ... I do not understand what he was trying to achieve.

    Ditto.

  • Ouch! (unregistered) in reply to Sigh
    Sigh:
    First clue is Boolean.FALSE. That's the constant replacement for the Boolean type false. He used the Object reference rather than the primitive because the method compareTo (implements the Comparable interface) takes an object. Camel-case is the preferred standard for variable naming, which they got right.
    Still doesn't prove it, with appropriate definitions in scope, it could be C, C++, C# and probably a fistful of languages more. So technically bertram is right, nothing guarantees it's Java. But it's very unlikely to be anything else.
  • ipeet (cs) in reply to frits
    frits:
    Matt K:
    frits:
    This is only a WTF if statusIsNotValid is a boolean. If it is some other type, this really isn't much of a WTF.

    Troll or idiot?

    The answer to your question is yes. ;)

    If statusIsNotValid is some other type, one could implement compareTo to return 0 for Boolean.FALSE if some special condition exists. This would be a little strange, but could be documented elsewhere. Based on this one line of code there isn't enough information about statusIsNotValid to definitively say this is as convoluted as most of you are assuming it is. Remember, assumption is the mother of all f*** ups.

    So, basically, the snippet isn't as bad as it looks so long as statusIsNotValid is an instance of a terribly designed class? (It has highly non-intuitive, unnecessary, special case behaviour which can only be discovered through reading the documentation [which is likely old and wrong by now])

    I can see how that makes this less of a WTF.

  • Mcoder (cs) in reply to Cbuttius
    Cbuttius:
    Oh well, C++ is so much simpler sometimes with operator overloading.

    Oh, came on. My head was already hurting after trying (uncessfull, it needs too many assumptions) to decode that piece of code. Now, you want me to think about what that developer could have done with operator overloading? That sentence would turn out to be some quite mundane:

    if(statusIsNotValid * false) skipValidation--;

    And all that preserving the meaning (whatever it is).

  • frits (cs) in reply to ipeet
    ipeet:
    frits:
    Matt K:
    frits:
    This is only a WTF if statusIsNotValid is a boolean. If it is some other type, this really isn't much of a WTF.

    Troll or idiot?

    The answer to your question is yes. ;)

    If statusIsNotValid is some other type, one could implement compareTo to return 0 for Boolean.FALSE if some special condition exists. This would be a little strange, but could be documented elsewhere. Based on this one line of code there isn't enough information about statusIsNotValid to definitively say this is as convoluted as most of you are assuming it is. Remember, assumption is the mother of all f*** ups.

    So, basically, the snippet isn't as bad as it looks so long as statusIsNotValid is an instance of a terribly designed class? (It has highly non-intuitive, unnecessary, special case behaviour which can only be discovered through reading the documentation [which is likely old and wrong by now])

    I can see how that makes this less of a WTF.

    Nice strawman. Sometimes you have to consume classes you didn't design. All my original post was pointing out was that we could use more information. Any comments on this particular line of code are purely conjecture. Including my own.

  • lupo (cs) in reply to Ouch!
    Ouch!:
    But it's very unlikely to be anything else.
    I think it's more of very likely to be nothing else
  • Ken B. (unregistered) in reply to Robert
    Robert:
    TheRealWTF:
    The Real WTF is that Alex totally missed out FILE_NOT_FOUND.
    and what about XOR
    That's just "or and not and".

    a XOR b == (a OR b) AND NOT (a AND b)

  • Mason Wheeler (cs)

    Maybe the author's first language is Spanish, in which double/triple/multiple negatives are not frowned upon the way they are in English, but required by the grammar.

    Ex: "No hacia nada con nadie" is a valid, standard sentence. Literally translated: "I didn't do nothing with nobody."

Leave a comment on “Boolean Illogic”

Log In or post as a guest

Replying to comment #:

« Return to Article