• ka1n (unregistered)

    Let me guess...you were debugging code written by Oracle...

  • bguff (unregistered)

    Could they be trying to place a breakpoint within the method, so that anytime boolean is false debugger breaks? Otherwise, i'm with everyone else.

  • Double Indemnity (unregistered)
    boolean response = false;
       if (value == true) {
           response = false;
    This is a technique you may see in certain mission critical situations. Similar to two-factor authentication, it is known as a two-factor write. Once a variable has been initialized with a value, if you need to make really really sure, you should store the same value there again. It more firmly embeds the bits pattern, or in this case, just the single bit.

    In most applications where performance is the key criteria and a moderate error rate is acceptable, this double redundancy is optional.

    (In our next lesson, we will discuss introducing a "chaos block" into the code, to complicate things enough that the compiler cannot optimize away the redundant write. Since this will necessarily involve a maze of increment and conditional branch instructions to foil the optimizer, comments should be omitted from this region for performance tuning purposes.)

  • davee123 (unregistered) in reply to THG
    THG:
    Where is its counterpart, isBooleanTrue() ?!?

    Oh, it's there-- you just got the name wrong. It's called isBooleanNotFalse().

    DaveE

  • Buddy (unregistered) in reply to Uncle Al
    Uncle Al:
    This is actually quite common in embedded systems...

    I think we need a WTF in FORTH or equivalent, just to get "embedded systems" the star treatment it deserves.

  • (cs) in reply to Jaime
    Jaime:
    //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.

    Funny, I was thinking this looked like the work of someone fresh out of school!

  • SeanJA (unregistered) in reply to bryan986

    Shouldn't it be:

    return (boolean)!value;

  • eyes (unregistered)

    yawn So unimpressive. Show me an implementation for isBooleanFish(), and I'll be impressed.

  • (cs) in reply to Double Indemnity
    Double Indemnity:
    boolean response = false;
       if (value == true) {
           response = false;
    This is a technique you may see in certain mission critical situations. Similar to two-factor authentication, it is known as a two-factor write. Once a variable has been initialized with a value, if you need to make really really sure, you should store the same value there again. It more firmly embeds the bits pattern, or in this case, just the single bit.

    In most applications where performance is the key criteria and a moderate error rate is acceptable, this double redundancy is optional.

    (In our next lesson, we will discuss introducing a "chaos block" into the code, to complicate things enough that the compiler cannot optimize away the redundant write. Since this will necessarily involve a maze of increment and conditional branch instructions to foil the optimizer, comments should be omitted from this region for performance tuning purposes.)

    There's no need to reset the variable so soon. You need to reset it thirty or forty lines further down when the charge may have leaked away from capacitors.

  • Morry (unregistered)

    I will admit that I have made something akin to the isBooleanFalse() function, but for the following reason: readability. Instead of something like

    if (foo && (! ptr1->rec2.substructC.indicatorN))

    I've created something like:

    if (foo && isSituationResolved(ptr1))

    where isSituationResolved is obviously just an encapsulation of the above code. Because it reads better and has about 100x the amount of information in it. Clarity, many times, is more important than brevity.

  • (cs) in reply to Brian follower of Deornoth
    Brian follower of Deornoth:
    Double Indemnity:
    boolean response = false;
       if (value == true) {
           response = false;
    This is a technique you may see in certain mission critical situations. Similar to two-factor authentication, it is known as a two-factor write. Once a variable has been initialized with a value, if you need to make really really sure, you should store the same value there again. It more firmly embeds the bits pattern, or in this case, just the single bit.

    In most applications where performance is the key criteria and a moderate error rate is acceptable, this double redundancy is optional.

    (In our next lesson, we will discuss introducing a "chaos block" into the code, to complicate things enough that the compiler cannot optimize away the redundant write. Since this will necessarily involve a maze of increment and conditional branch instructions to foil the optimizer, comments should be omitted from this region for performance tuning purposes.)

    There's no need to reset the variable so soon. You need to reset it thirty or forty lines further down when the charge may have leaked away from capacitors.

    For that you'd need to implement a high precision timer, so you can be sure a uniform wait is always observed. None of this Sleep() nonsense either, you need to access the system clock directly. However, a much more elegant solution is to entangle the two variables. That way, when you read either one, you will instantly know the value of the other.

  • wtf (unregistered) in reply to Double Indemnity
    Double Indemnity:
    It more firmly embeds the bits pattern, or in this case, just the single bit.

    Curiously enough, the jvm has no provisions for dealing with single bits. Booleans are treated as ints, internally. (see jvm 3.3.4, or javap some code and see what it looks like to the machine)

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

    FTFY

    Win!
  • (cs)

    Your friend was a poet: isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(toDie))))))))

  • Scotty (unregistered) in reply to Burpy
    Burpy:
    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.)
    "bool" is just ASCII-art for a string of ones and zeros (10001) which helps programmers remember that there are actual bits down there somewhere in the basement.
  • somedude (unregistered)

    This should be serialized to XML to make it better.

  • Engineer (unregistered) in reply to Brian follower of Deornoth
    Brian follower of Deornoth:
    Double Indemnity:
    boolean response = false;
       if (value == true) {
           response = false;
    This is a technique you may see in certain mission critical situations. Similar to two-factor authentication, it is known as a two-factor write. Once a variable has been initialized with a value, if you need to make really really sure, you should store the same value there again. It more firmly embeds the bits pattern, or in this case, just the single bit.

    In most applications where performance is the key criteria and a moderate error rate is acceptable, this double redundancy is optional.

    (In our next lesson, we will discuss introducing a "chaos block" into the code, to complicate things enough that the compiler cannot optimize away the redundant write. Since this will necessarily involve a maze of increment and conditional branch instructions to foil the optimizer, comments should be omitted from this region for performance tuning purposes.)

    There's no need to reset the variable so soon. You need to reset it thirty or forty lines further down when the charge may have leaked away from capacitors.

    Yes, but with today's nanometer scale technologies, there's so much less charge to leak, and the leakage currents are so much higher that it requires frequent resetting of values to ensure optimal performance

  • Jack (unregistered)
    bool isThatFunctionTellingTheTruth(bool ans) {
      return true; // captcha luptatum
    }
    
  • Ralph (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.
    Actually that's all they're hiring these days. The Managers' Union for Promoting Technical Ignorance (MUPTI) has alerted its membership that experienced developers tend to raise issues that delay the delivery date.
  • unekdoud (unregistered)

    Ouch!

    #define IsBooleanFalseUntrueOrotherwiseDishonest(PossiblyFalseValue) (PossiblyFalseValue == (0 == 1) ? (1 == 1) : (((PossiblyFalseValue || (1 == 0)) && PossiblyFalseValue)?(0 == 1):(0 == 0)))

    Captcha: causa... this codes gonna causa lotta wtf?

  • codingmommy (unregistered) in reply to Anonymous
    Anonymous:
    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.

    Where "it" is a wooden table...

  • Zen (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.

    Let me introduce you to Paula Bean:

    http://thedailywtf.com/Articles/The_Brillant_Paula_Bean.aspx

  • neminem (unregistered) in reply to Anonymous
    Anonymous:
    Additionally, you must always remember that the true values of a boolean are TRUE, FALSE and FILE_NOT_FOUND.
    You know... people keep making fun of that, but at least it's an actual tri-state bool. I'd much rather have true/false/FNF than this "tri"-state "bool" that actually has 5 states, courtesy of Microsoft. At least FNF tells you what it's for, unlike CTrue.
  • Clueless newbie (unregistered) in reply to ais523
    ais523:
    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).

    Congratulations, you've won this thread. Please stop by the league offices to pick up your internets any time after Tuesday.

  • (cs) in reply to Anonymous
    Anonymous:
    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 sanity in the IT industry.

    FTFY

  • anon (unregistered) in reply to neminem
    neminem:
    Anonymous:
    Additionally, you must always remember that the true values of a boolean are TRUE, FALSE and FILE_NOT_FOUND.
    You know... people keep making fun of that, but at least it's an actual tri-state bool. I'd much rather have true/false/FNF than this "tri"-state "bool" that actually has 5 states, courtesy of Microsoft. At least FNF tells you what it's for, unlike CTrue.

    TRWTF is that three of those five are marked "not supported".

  • ExpatEgghead (unregistered) in reply to Anon
    Anon:
    There you go, much better (and more complete):

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

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

    Oooh! such a warm fuzzy feeling now.

  • anonymous (unregistered) in reply to neminem

    in other news, MS is now competing with thedailywtf

  • Herby (unregistered)

    This reminds me of an article in a trade rag (I believe it was Datamation) that showed various responses to an interview question: "Write a routine that takes a variable that has the value of 1 and 2 and returns the other one (use any language)". The responses were just as verbose and usually wrong. Many had no error checking (not really a requirement), and all but one were as long at this. The winner was: return 3-input [or its equivalent]. It IS an interesting question to ask on interviews. I don't know how Paula Bean would answer it!

  • Herby (unregistered)

    OK, I'll bite. What is an "auto-boxer"?

    I did a search and it turns out it isn't "auto-briefs"!

  • Listconnt Smalle (unregistered) in reply to unekdoud
    unekdoud:
    Ouch!

    #define IsBooleanFalseUntrueOrotherwiseDishonest(PossiblyFalseValue) (PossiblyFalseValue == (0 == 1) ? (1 == 1) : (((PossiblyFalseValue || (1 == 0)) && PossiblyFalseValue)?(0 == 1):(0 == 0)))

    Very well indeed.

    In our programmes, we do indeed prefer to employ some definitions like those shown below in order to rid ourselves from some of the vulgarity found in those newfangled programming languages.

    #define dishonest false
    #define sincere true
    #define George_Boole_s_Type bool
    
  • fjf (unregistered) in reply to Codism
    Codism:
    Your friend was a poet: isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(toDie))))))))
    isBooleanEitherOr(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(toBe)))),isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(isBooleanFalse(toBe))))))
  • fjf (unregistered) in reply to Knux2
    Knux2:
    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;
    }
    
    OK, you got the logging stuff right, very good. (Though you might want to consider migrating to our new logging manager factory templates.)

    But where's the exception handling? Don't know you know that every function must have at least one try..catch block?

    Also, for our next code review, I expect an appropriate number of units test for this complex function.

  • sam (unregistered)

    it's a gem!, not an example of over-engineering

    it's a gem

  • CodeGuy (unregistered) in reply to Burpy

    Clearly "bool" is just "noob" backwards.

  • EngleBart (unregistered)

    Where was the frist guy today? I was expecting a gem from this article...

    I can't stand to even look at code like this:

    if (checkIt() == false)

    since I think

    if (!checkIt())

    works better. Some of the posts were like nails on a chalkboard!

    Another pet peeve. It takes an extra few seconds to figure out the check blocks.

    boolean notFound = true; while (notFound == true) { // try to find it I think... if (...) notFound = false; }

    vs.

    boolean found = false; while (!found) { // try to find it, I am sure if (...) found = true; }

  • (cs) in reply to Herby
    Herby:
    OK, I'll bite. What is an "auto-boxer"?

    I did a search and it turns out it isn't "auto-briefs"!

    Java has two types of values: primitive types and Object types. Each primitive type has a corresponding wrapper class that allows it to be used in a context that requires an Object type.

    The process of converting a primitive type to its corresponding object wrapper type is called "boxing". The reverse is "unboxing". Since Java 1.5, this process is performed automatically at compile time in most situations. This is called "auto-boxing" or "auto-unboxing".

  • Fenris (unregistered) in reply to Morry

    In your case, the info that you are adding with your encapsulation is not about that little "!" is about the meaning of ptr1->rec2.substructC.indicatorN

  • NutDriverLefty (unregistered) in reply to neminem
    neminem:
    I'd much rather have true/false/FNF than this "tri"-state "bool" that actually has 5 states, courtesy of Microsoft. At least FNF tells you what it's for, unlike CTrue.

    It's still a tri-state because three of the states are described as "Not Supported". Apparently, only msoTrue and msoFalse are actually supported, of the five defined states.

  • Befuddled (unregistered) in reply to Double Indemnity

    The saddest thing is I know at least one "chief architect" who would be nodding sagely whilst reading this post.

  • CoderDan (unregistered) in reply to Matt Westwood

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

    is shorter and doesn't include !

    or

    return (value == false);

  • the beholder (unregistered) in reply to Herby
    Herby:
    OK, I'll bite. What is an "auto-boxer"?

    I did a search and it turns out it isn't "auto-briefs"!

    [image]That guy ^^

  • (cs) in reply to Herby
    Herby:
    "Write a routine that takes a variable that has the value of 1 and 2 and returns the other one (use any language)".
    Oh boy, Schrödinger variables!
  • Ralph (unregistered) in reply to Zylon
    Zylon:
    Herby:
    "Write a routine that takes a variable that has the value of 1 and 2 and returns the other one (use any language)".
    Oh boy, Schrödinger variables!
    Interview questions like this are a trick. A freshout CS major will think "oh goody I get to design an algorithm!" Anyone with real world experience will realize this -- as usual -- is a poorly defined requirement. This will give the interviewer a chance to observe the candidate's requirements gathering skillz. So the correct response is:

    "Everyone knows the value of 1 and 2 is zero, so that's always going to be the input. When you say 'returns the other one' I assume you mean that the function should simply return a '1'. Do you want that as an integer, float, or ASCII character?"

  • Mr.'; Drop Database -- (unregistered)
    public boolean isBooleanFalse(boolean value) {
        return !isBooleanTrue(value);
    }
    public boolean isBooleanTrue(boolean value) {
        return !isBooleanFalse(value);
    }
  • fjf (unregistered) in reply to Ralph
    Ralph:
    Zylon:
    Herby:
    "Write a routine that takes a variable that has the value of 1 and 2 and returns the other one (use any language)".
    Oh boy, Schrödinger variables!
    Interview questions like this are a trick. A freshout CS major will think "oh goody I get to design an algorithm!" Anyone with real world experience will realize this -- as usual -- is a poorly defined requirement. This will give the interviewer a chance to observe the candidate's requirements gathering skillz. So the correct response is:

    "Everyone knows the value of 1 and 2 is zero, so that's always going to be the input. When you say 'returns the other one' I assume you mean that the function should simply return a '1'. Do you want that as an integer, float, or ASCII character?"

    To which the correct response by the interviewer is:

    "You know, when dealing with customers we prefer employees who don't try to make them look like idiots, even if their natural language descriptions dont translate 1:1 to a computer program. (Hint: That's your job as a programmer.) There's nothing wrong with clarifying unclear requirements, but deliberately misinterpreting something whose meaning is clear with a little common sense isn't helpful. Thank you for taking the time."

  • (cs) in reply to Buddy
    Buddy:
    Uncle Al:
    This is actually quite common in embedded systems...

    I think we need a WTF in FORTH or equivalent, just to get "embedded systems" the star treatment it deserves.

    : IsNotFalse ( n -- n )
      0 =
      if
        0
      else
        -1
      then
    ;
    

    There's for Forth for ya. And FWIW, there is no equivalent to Forth. Unless it would be APL.

  • wang (unregistered)

    fritz

  • fjf (unregistered) in reply to RogerC
    RogerC:
    Buddy:
    Uncle Al:
    This is actually quite common in embedded systems...

    I think we need a WTF in FORTH or equivalent, just to get "embedded systems" the star treatment it deserves.

    : IsNotFalse ( n -- n )
      0 =
      if
        0
      else
        -1
      then
    ;
    

    There's for Forth for ya. And FWIW, there is no equivalent to Forth. Unless it would be APL.

    Well, there's PostScript:
    /isBooleanFalse { false eq } bind def
    Or more in the spirit of the WTF:
    /isBooleanFalse { false ne { false } { true } ifelse } bind def
  • hoodaticus (unregistered)

    At first, it seems like a shallow, simple WTF. But the more you examine the code, the more you appreciate its subtle layers of ingenious WTFery.

    The first layer of WTF one encounters is in this precious line:

    public boolean isBooleanFalse(boolean value) {

    which would make the first WTF the notion that this function, which costs 17+Len(Expression) keystrokes to call, would be superior to: (Expression). The second WTF on this, the first line of code, is that, well, if I were to intentionally create something like this, there is no fucking way I would expose it to my public API.

    But it gets better. The second line of code is:

    boolean response = false;

    Which translates in at least four different languages to:

    world.laugh(me);

    Then we come to the fifth WTF on the next two lines:

    if (value == true) { response = false;

    which wastefully performs conditional processing on an unconditional task, i.e. response = !value.

    The sixth layer of WTFery is on the last line of code:

    return response;

    Since it should have been "return !value;" and just eliminate every other line of code in the function, assuming the function is needed at all, which it's not (WTF#7).

    That's seven WTF's in seven lines of code, which is WTF#8.

Leave a comment on “Bulletproofed Boolean”

Log In or post as a guest

Replying to comment #:

« Return to Article