• hoodaticus (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); }

    I ALMOST PEED!!!

  • Senthil Balakrishnan (unregistered)

    What's wrong with this code ?

    It's a "boolean" and not "Boolean", so the only thing that can be passed to that method is "true" or "false" and noway a null on a primitive isn't it ?

    I guess you meant Boolean.

  • Nick (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 !
    He must also be new to the software development industry...
  • Nick (unregistered) in reply to Senthil Balakrishnan
    Senthil Balakrishnan:
    What's wrong with this code ?

    It's a "boolean" and not "Boolean", so the only thing that can be passed to that method is "true" or "false" and noway a null on a primitive isn't it ?

    I guess you meant Boolean.

    Actually, in Java 5 and above you can pass in null. Thank you auto-boxing.

  • Nick (unregistered) in reply to eyes
    eyes:
    *yawn* So unimpressive. Show me an implementation for isBooleanFish(), and I'll be impressed.
    public boolean isBooleanFish(boolean bool){
      return (new Fish()).equals(Boolean.valueOf(bool));
    }
    
    Funny thing is, that could be true, depending on how Fish implements equals.
  • Swedish tard (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.

    Landing a job requires a different skillset than performing the job. In pretty much any job except sales.

  • blunder (unregistered) in reply to Nick
    Nick:
    Senthil Balakrishnan:
    What's wrong with this code ?

    It's a "boolean" and not "Boolean", so the only thing that can be passed to that method is "true" or "false" and noway a null on a primitive isn't it ?

    I guess you meant Boolean.

    Actually, in Java 5 and above you can pass in null. Thank you auto-boxing.

    Not to a function that doesn't take Booleans, you can't.

  • Burpy (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?

    If you had enough time to read the entirety of the back archive, you must have read things about people reading the entirety of back archives while their fellow co-workers tried to code the soft for the deadline... :)

  • Grant D. Noir (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.

    Sometimes the recruiting process is best characterized as a stochastic one, and in the end of the day, all it takes is an equally f-ed up hiring manager.

    And do they exist? Well as Jamie and Adam would put it: "Myth Confirmed".

  • anon (unregistered)

    If that code is in C#, maybe the intent was to include a "?" in the method argument so that "value" could be nullable. In that case, the method would probably have made more sense.

  • (cs)

    This is C code, but i'm sure it would be easy to port to other languages:

    bool get_value_of_true( void )
    {
      FILE *f;
      char xmlfile[2048];
      int i, v=0;
      bool true_value;
    
      f = fopen( "true_or_false.xml", "r" );
      fread( xmlfile, 1, 2048, f );
      fclose( f );
    
      for( i=0; i<2048; i++ )
      {
        if( ( xmlfile[i] == '<' ) &&
            ( xmlfile[i+1] == 't' ) &&
            ( xmlfile[i+2] == 'r' ) &&
            ( xmlfile[i+3] == 'u' ) &&
            ( xmlfile[i+4] == 'e' ) &&
            ( xmlfile[i+5] == '>' ) )
        {
          i += 6;
          while( (xmlfile[i]>='0') && ( xmlfile[i]<='9') )
          {
            v = v * 10;
            v = v + (xmlfile[i]-'0');
            i++;
          }
    
          true_value = (bool)v;
          return true_value;
        }
      }
    
      return true;
    }
    
    bool get_value_of_false( void )
    {
      FILE *f;
      char xmlfile[2048];
      int i, v;
      bool false_value;
    
      f = fopen( "true_or_false.xml", "r" );
      fread( xmlfile, 1, 2048, f );
      fclose( f );
    
      for( i=0; i<2048; i++ )
      {
        if( ( xmlfile[i] == '<' ) &&
            ( xmlfile[i+1] == 'f' ) &&
            ( xmlfile[i+2] == 'a' ) &&
            ( xmlfile[i+3] == 'l' ) &&
            ( xmlfile[i+4] == 's' ) &&
            ( xmlfile[i+5] == 'e' ) &&
            ( xmlfile[i+6] == '>' ) )
        {
          i += 7;
          while( (xmlfile[i]>='0') && ( xmlfile[i]<='9') )
          {
            v = v * 10;
            v = v + (xmlfile[i]-'0');
            i++;
          }
    
          false_value = (bool)v;
          return false_value;
        }
      }
    
      return false;
    }
    
    bool isBooleanFalse( bool value )
    {
      bool response;
    
      response = get_value_of_false();
    
      if( value == get_value_of_false() )
      {
        response = get_value_of_true();
      }
      else if( value == get_value_of_true() )
      {
        response = get_value_of_false();
      }
      else
      {
        return !value;
      }
    
      return response;
    }
    

    Hmm... annoyingly the code tag seems to make it double spaced :-(

  • Grumpy (unregistered) in reply to Xeron
    Xeron:
    This is C code, but i'm sure it would be easy to port to other languages:
    <snip>
    

    Hmm... annoyingly the code tag seems to make it double spaced :-(

    Enterprisey C - genius!

  • (cs)

    IsTrue(IsNotTrue(IsBooleanTrue(IsBooleanFalse(I_Dont_Know))))

    Comment made with the EVE Online browser

  • History Teacher (unregistered)

    The longer the code, the more bug-free it is, because writing longer code takes more effort, and squashing bugs is a lot of effort, so more effort logically leads to less bugs.

  • Anon (unregistered) in reply to fjf
    fjf:
    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."

    QFT.

  • Jim (unregistered)

    Please someone do a webservice with it, because I don't know which implementation to choose for this function.

    Thanks in advance !

  • Hans (unregistered) in reply to Anonymouse

    No, there is no defense for this type of programming.

  • Drew (unregistered)

    Clearly the man was getting paid by the line. In that essence, this is genius.

  • (cs) in reply to THG
    THG:
    Where is its counterpart, isBooleanTrue() ?!?
    You can use
    !isBooleanFalse()
    for that.
  • cappeca (unregistered)

    It should give the answer in XML.

  • Jay (unregistered) in reply to prionic6
    prionic6:
    At least
    response
    was initialized.

    It had to be initialized so just in case the value was neither equal to false nor not equal to false and so neither end of the IF executes, it would not be undefined.

  • Jay (unregistered) in reply to Nick
    Nick:
    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 !
    He must also be new to the software development industry...

    And to the human race ...

  • Jay (unregistered) in reply to Someone You Know
    Someone You Know:
    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".

    Ohhh!! I thought an auto-boxer was a guy who has fist-fights with cars.

  • Press The Red Button (unregistered) in reply to Herby
    Herby:
    "...Write a routine that takes a variable that has the value of 1 and(sic) [OR?] 2 and returns the other one (use any language)". The responses were just as verbose and usually wrong...

    It would be interesting to stipulate that you could not use any language conditional logic in your answer...

  • Press The Red Button (unregistered) in reply to Anon
    Ralph:
    So the correct response is:

    "Everyone knows the value of 1 and 2 is zero...

    string value = "1 and 2";

    value comparison with (int)0 is meaningless value != "zero"

  • sam (unregistered) in reply to Daniel Fountain

    Its a never ending coding loop!!!!!!!!!!!!! == infinite recursion

  • silverpie (unregistered) in reply to eyes

    return !isBooleanFowl

  • silverpie (unregistered) in reply to eyes
    eyes:
    *yawn* So unimpressive. Show me an implementation for isBooleanFish(), and I'll be impressed.
    return !isBooleanFowl (after quote fail in previous attempt)
  • Bubba (unregistered) in reply to Jay
    Jay:
    And to the human race ...

    It's a Victorian throwback to refer to Homo sapiens that way. Technically we (or on this forum, at least the vast majority) are members of the human species, but we don't like to think of ourselves as being just another animal.

  • (cs) in reply to Bubba
    Bubba:
    Jay:
    And to the human race ...

    It's a Victorian throwback to refer to Homo sapiens that way. Technically we (or on this forum, at least the vast majority) are members of the human species, but we don't like to think of ourselves as being just another animal.

    Mitch Hedberg:
    I went to a heavy metal concert. The singer yelled out, "How many of you people feel like human beings tonight?" And then he said, "How many of you feel like animals?" The thing is, everyone cheered after the animals part, but I cheered after the human beings part because I did not know there was a second part to the question.
  • WhiteWizzard (unregistered)

    This happens all the time at my company, they call it "BTC" or before time code. This is compounded by the fact that I see new users doing the same thing. . ..

  • Hector (unregistered)

    I think I know the person who wrote this code! It's the same person who also authored the code below:

    // If true return inVal1 else return inVal2 // public double IfThenElse(bool inCond, double inVal1, double inVal2) { if (inCond) { return inVal1; } else { return inVal2; } }

    Hector

  • Java Refugee (unregistered)

    Boolean.TRUE.equals(value) if you really need to be that paranoid about the value in question, and I sincerely doubt that.

  • rcopley (unregistered) in reply to THG

    no, he just figured that since he had isBooleanFalse() already written; he could just use !isBooleanFalse(x);

  • fjf (unregistered) in reply to Hector
    Hector:
    I think I know the person who wrote this code! It's the same person who also authored the code below:

    // If true return inVal1 else return inVal2 // public double IfThenElse(bool inCond, double inVal1, double inVal2) { if (inCond) { return inVal1; } else { return inVal2; } }

    Hector

    Perfectly reasonable in environments where "? :" is banned.

    (I.e., stupid restrictions => stupid workarounds.)

  • validus (unregistered) in reply to Hector

    Seems he's improving as he didn't call IsBoolFalse() - he didn't even write "if (inCond == true)".

    Maybe there's hope for him yet, but I still wouldn't hire him.

    We need a "double-checking booleans is broken" declaration in the spirit of the "double-checking locks is broken" declaration.

  • neelesh (unregistered) in reply to Knux2

    Not enterprisey enough. Where is my XML?

    captcha: ingenium - ingenious gum? or slot #120 on the periodic table?

  • plasmab (unregistered)

    I see this sort of crap all the time.

    I've even seen

    if (condition) { MethodA(); } else { MethodA(); }

  • Jjmmhggg (unregistered)

    Vfxcbhhn. Bhun Great job cleaning input... NOT!!!!!I

  • R (unregistered) in reply to bryan986

    Even shorter: Never even have that method

  • shill (unregistered)
    public boolean isBooleanFalse(boolean value) {
       // use NORs to simulate a NAND simulating a NOT
       return !(!(!(value || value) || !(value || value)) || !(!(value || value) || !(value || value)))
    }
  • Johnette (unregistered)

    Hi would you mind sharing which blog platform you're using? I'm planning to start my own blog in the near future but I'm having a hard time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I'm looking for something completely unique.

    P.S Sorry for getting off-topic but I had to ask! donate for ukraine

Leave a comment on “Bulletproofed Boolean”

Log In or post as a guest

Replying to comment #:

« Return to Article