• //Rumen (unregistered)

    Wow.... why does this happen so often?

  • (cs)

    That piece code is awesome!

    Addendum (2010-07-14 09:58): I see Mark B. fixed his typo. Oh well.

  • (cs)

    Maybe the friend doesn't like the exclamation mark in code? It's not easy to make this code shorter and not use an exclamation mark or question mark.

    Reminds me of some code I saw once, which compared whether a certain integer was greater than 4 and less than 6.

  • Matt Westwood (unregistered) in reply to Severity One
    Severity One:
    Maybe the friend doesn't like the exclamation mark in code? It's not easy to make this code shorter and not use an exclamation mark or question mark.

    Reminds me of some code I saw once, which compared whether a certain integer was greater than 4 and less than 6.

    if (value == false) { return true; } else { return false; }

    is shorter and doesn't include !

  • (cs) in reply to Matt Westwood
    Matt Westwood:
    Severity One:
    Maybe the friend doesn't like the exclamation mark in code? It's not easy to make this code shorter and not use an exclamation mark or question mark.

    Reminds me of some code I saw once, which compared whether a certain integer was greater than 4 and less than 6.

    if (value == false) { return true; } else { return false; }

    is shorter and doesn't include !

    return (value == false);
    
  • (cs) in reply to frits
    frits:
    Matt Westwood:
    Severity One:
    Maybe the friend doesn't like the exclamation mark in code? It's not easy to make this code shorter and not use an exclamation mark or question mark.

    Reminds me of some code I saw once, which compared whether a certain integer was greater than 4 and less than 6.

    if (value == false) { return true; } else { return false; }

    is shorter and doesn't include !

    return (value == false);
    
    return !value;
    
  • Anonymous (unregistered)

    It pains me to think that people like this are out there coding right now. Probably adding a few helper methods like IsIntEqualToOne(int i) and IsStringEqualToFudge(string possiblyFudge).

  • (cs) in reply to Matt Westwood

    Big bad boolean blunder built by belligerent baffoon.

    Alliteration FTW

  • prionic6 (unregistered)

    At least

    response
    was initialized.

  • Skilldrick (unregistered) in reply to Anonymous
    Anonymous:
    It pains me to think that people like this are out there coding right now. Probably adding a few helper methods like IsIntEqualToOne(int i) and IsStringEqualToFudge(string possiblyFudge).

    At least they're using descriptive names and parameters. Even better: int2(int x) {return x == 1;}

  • srejv (unregistered)

    public boolean isBooleanFalse(boolean value) { boolean response = true; if (value == true) { response = false; } return response; }

  • (cs) in reply to bryan986
    bryan986:
    frits:
    Matt Westwood:
    Severity One:
    Maybe the friend doesn't like the exclamation mark in code? It's not easy to make this code shorter and not use an exclamation mark or question mark.

    Reminds me of some code I saw once, which compared whether a certain integer was greater than 4 and less than 6.

    if (value == false) { return true; } else { return false; }

    is shorter and doesn't include !

    return (value == false);
    
    return !value;
    
    

    Reading is fundamental.

  • (cs) in reply to Skilldrick
    Skilldrick:
    At least they're using descriptive names and parameters. Even better: int2(int x) {return x == 1;}
    Better still would be int int86(int x) {return x == 86;}, just for the horrific breakage when ported to DOS (which probably wouldn't be noticed immediately).
  • Jukin (unregistered) in reply to frits
    frits:
    Matt Westwood:
    Severity One:
    Maybe the friend doesn't like the exclamation mark in code? It's not easy to make this code shorter and not use an exclamation mark or question mark.

    Reminds me of some code I saw once, which compared whether a certain integer was greater than 4 and less than 6.

    if (value == false) { return true; } else { return false; }

    is shorter and doesn't include !

    return (value == false);
    
    return value ^^ true;
    
  • endre (unregistered)

    we needed this, i stole it

  • THG (unregistered)

    Where is its counterpart, isBooleanTrue() ?!?

    (Do Code-Reviews, and you would catch these omissions)

    Also, maybe somebody else there has already written isBooleanFalse(), and Brian's friend is reinventing the wheel. __ /hg

  • Murf (unregistered)

    Yes bulletproofed. As long as no-one passes a null of course.

  • Kim (unregistered) in reply to Matt Westwood

    return value ^ true

    is also shorter and doesn't contain !

  • (cs)

    I can imagine calls to that function might look something like this:

    if isBooleanFalse(foo) == true {
        // foo is false, so do not do what we would have done.
        };
    
    if isBooleanFalse(foo) == false {
        // foo is not false, or true, reindex the nasa mainframe.
        };
    
  • (cs) in reply to Murf
    Murf:
    Yes bulletproofed. As long as no-one passes a null of course.
    Language comprehension is fundamental.

    To me, this code looks like Java. And Java distinguishes between primitive types and objects. boolean (lowercase) is a primitive type, where Boolean (uppercase) is an object. Objects can be null, primitives cannot. The parameter is declared boolean (the primitive type), therefore no null value possible there.

  • Murf (unregistered) in reply to TheRider

    Obviously you're not an auto-boxer.

  • Daniel Fountain (unregistered)

    So - if that checks if a boolean is false, and returns a boolean - should i use this function to check if this function returns a false boolean?

    Its a never ending coding loop!!!!!!!!!!!!!

    Dan

    www.3xg.co.uk

  • charles (unregistered) in reply to Jukin
    Jukin:
    frits:
    Matt Westwood:
    Severity One:
    Maybe the friend doesn't like the exclamation mark in code? It's not easy to make this code shorter and not use an exclamation mark or question mark.

    Reminds me of some code I saw once, which compared whether a certain integer was greater than 4 and less than 6.

    if (value == false) { return true; } else { return false; }

    is shorter and doesn't include !

    return (value == false);
    
    return value ^^ true;
    
    return value.toString().toWoodenTable().toString().equals(Boolean.FALSE.toString().toWoodenTable().toString()) == Boolean.TRUE.toString().toWoodenTable().toString();
    
  • (cs)

    I call bullshit! There's no friggin' way that someone smart enough to land a job could possibly be that fucked up.

  • Knux2 (unregistered)

    Weak. We can do better.

    public boolean isBooleanFalse(boolean value) {
       log.info("Entered isBooleanFalse");
       boolean response = false;
       if (value == null) {
           log.debug("value is NULL");
           response = false;
       } else if (value == true) {
           log.debug("value is true");
           response = false;
       } else {
           log.debug("value is not true or null");
           response = true;
       }
       log.debug("response is " + response);
       log.info("Leaving isBooleanFalse");
       return response;
    }
    
  • tragomaskhalos (unregistered) in reply to SuperJames74
    SuperJames74:
    I call bullshit! There's no friggin' *way* that someone smart enough to land a job could possibly be that fucked up.
    You must be new to theDailyWTF my friend !
  • George Fitch (unregistered)

    Obviously, the correct way of doing this would be to replace this function with a call to a web service that submits the boolean value to a MS SQL Server 2008 via stored procedure. The database would then return the correct value by means of a VarBinary(Max) value of a JPEG image of a scanned Polaroid photo of the word 'True' or 'False' written on different colored index cards photographed on a wooden table.

    ... or just not use the function in the first place.

  • Anonymouse (unregistered)

    Defensive programming.

  • Burpy (unregistered) in reply to SuperJames74

    My senior developer coworker once asked me what I meant when I was refering to "boolean"... and I've already seen this kind of crap in his code (but as he's a C# developer he uses "bool" and never asked himself where does this 4 letters word comes from.)

  • (cs) in reply to //Rumen
    //Rumen:
    Wow.... why does this happen so often?
    My guess is that somebody is having an internal conflict between strongly-typed code and dynamic code, and they aren't smart enough to realize it. This code looks like an attempt to coerce anything to a boolean (poorly).

    It's funny to watch people go back and forth between "strong typing seems to help the compiler find my errors" and "strong typing requires me to do these annoying casts". The result is often pseudo dynamic code in a strong typed language.

    These people need to read an article in a programming journal at least once per decade. Or maybe even go to school.

  • ell0bo (unregistered)

    Did you by chance arrange it so that his genetic material no longer has any change of propagating through the gene pool?

  • monkeyPushButton (unregistered) in reply to tragomaskhalos
    tragomaskhalos:
    SuperJames74:
    I call bullshit! There's no friggin' *way* that someone smart enough to land a job could possibly be that fucked up.
    You must be new to theDailyWTF my friend !
    That's right SuperJames, no one that stupid could get a job in development. And santa is watching you. And the toothfairy brought you that shiny new quarter. And scruffy is playing happily on a farm in the country.
  • (cs) in reply to SuperJames74
    SuperJames74:
    I call boolshit! There's no friggin' *way* that someone smart enough to land a job could possibly be that fucked up.

    FTFY

  • (cs)

    I love this site...

  • Anonymous (unregistered) in reply to SuperJames74
    SuperJames74:
    I call bullshit! There's no friggin' *way* that someone smart enough to land a job could possibly be that fucked up.
    Ahh, a newcomer. Welcome my friend, pull up a seat and prepare to lose any preconceptions you have of professionalism in the IT industry.
  • Antony Koch (unregistered)

    return !(false & !!!x)

  • Antony Koch (unregistered) in reply to Antony Koch

    oops!

    return !(false & !!!value)

  • Anon (unregistered)

    There you go, much better (and more complete):

    public boolean isBooleanFalse(boolean value) { return !isBooleanTrue(value); }

    public boolean isBooleanTrue(boolean value) { return !isBooleanFalse(value); }

  • JohnMcG (unregistered)

    The great thing about this is that it can be re-used to write isBooleanTrue...

    public boolean isBooleanTrue(boolean value)
    {
       return isBooleanFalse(isBooleanFalse(value));
    }
    

    Or, to keep the style consistent

    public boolean isBooleanTrue(boolean value)
    {
       boolean response = true;
       if (isBooleanFalse(value)) {
          response = false;
       } else {
          response = true;
       }
       return response;
    }
    
  • Some Wonk (unregistered) in reply to endre
    endre:
    we needed this, i stole it

    No, no, no. The proper response is "Plz send teh codez"

  • Professor Shitston Piss Phd. (unregistered) in reply to Knux2
    Knux2:
    Weak. We can do better. ...crap...

    You forgot to use IoC

    public boolean isBooleanFalse(boolean value) {
       log.info("Entered isBooleanFalse");
       boolean response = IoC.Resolve<IBoolean>("FalseBoolean");
       if (value == null) {
           log.debug("value is NULL");
           response = IoC.Resolve<IBoolean>("FalseBoolean");
       } else if (value == true) {
           log.debug("value is true");
           response = IoC.Resolve<IBoolean>("FalseBoolean");
       } else {
           log.debug("value is not true or null");
           response = IoC.Resolve<IBoolean>("TrueBoolean");
       }
       log.debug("response is " + response);
       log.info("Leaving isBooleanFalse");
       return response;
    }
    
  • (cs) in reply to Severity One
    Severity One:
    It's not easy to make this code shorter and not use an exclamation mark or question mark.
    public boolean isBooleanFalse(boolean value) {
       return value == false
    }
    Placing the code inline is even shorter, without ! or ?
  • (cs) in reply to Murf
    Murf:
    Obviously you're not an auto-boxer.

    And obviously you don't have the slightest clue how auto-boxing works. Well, auto unboxing since that's the only thing that would be affected here.

    In Java, even if you have a Boolean that needs to be auto unboxed into a boolean, it will happen in client code before the call to isBooleanFalse. There is positively NOTHING the library function could do, or should do, to change that.

  • SR (unregistered) in reply to SuperJames74
    SuperJames74:
    I call bullshit! There's no friggin' *way* that someone smart enough to land a job could possibly be that fucked up.

    You're very lucky to work in such a competent team.

  • Jason Y (unregistered) in reply to prionic6

    That depends on the language. If it requires initialization before use, then initializing it to a potentially wrong value is bad. If it does not require initializing, then initializing to a potentially right valid value is OK (though initializing to an invalid value like null is better, if you have the option).

    Anyway, this example code isn't over-engineering, and isn't making anything more bullet-proof. It's just a very verbose way to implement the not operator.

  • Jason Y (unregistered) in reply to Knux2

    Now that is over-engineering!

    captcha: jumentum - momentum initialized by a jump.

  • neminem (unregistered) in reply to Anonymous
    Anonymous:
    Ahh, a newcomer. Welcome my friend, pull up a seat and prepare to lose any preconceptions you have of professionalism in the IT industry.
    Well, I'm a newcomer too. I just started by reading the entirety of the back archives, so that I can reference all your memes: it's not enterprisey enough - where's the xml?

    See?

  • Uncle Al (unregistered) in reply to Severity One
    Severity One:
    Maybe the friend doesn't like the exclamation mark in code? It's not easy to make this code shorter and not use an exclamation mark or question mark.

    This is actually quite common in embedded systems where exclamation points and question marks have been removed to produce a reduced character set.

  • Anonymous (unregistered) in reply to neminem
    neminem:
    Anonymous:
    Ahh, a newcomer. Welcome my friend, pull up a seat and prepare to lose any preconceptions you have of professionalism in the IT industry.
    Well, I'm a newcomer too. I just started by reading the entirety of the back archives, so that I can reference all your memes: it's not enterprisey enough - where's the xml?

    See?

    Not bad but you need to add some embedded file systems, a bit of EVE Online, some Irish Girl and an honorable mention to Paula, Lyle and Rumen. Additionally, you must always remember that the true values of a boolean are TRUE, FALSE and FILE_NOT_FOUND.

    There, I think that just about covers it.

  • North Shore Beach Bum (unregistered) in reply to Murf
    Obviously you're not an auto-boxer.

    The compiler converts auto unboxing with a call to .booleanValue(). This would produce a runtime NullPointerException. By using a primitive as an argument, you guarantee that it will not be null. By using a primitive as a return type, you declare the method will not return null.

    I've seen similar code which takes a Boolean as a parameter and returns a boolean just to avoid dealing with NPEs. In such code, null is treated as false.

Leave a comment on “Bulletproofed Boolean”

Log In or post as a guest

Replying to comment #:

« Return to Article