• (cs)

    I have done a fair amount of Java, and have never used the Boolean, non-primitive type. Truly baffling... Is this rendition.....not the same?

    public boolean checkFalse(Boolean bool) { return bool.booleanValue(); }

    Are there websites that offer examples of really well-written code?

  • (cs) in reply to jb

    Anonymous:
    and when bool is null, you get a nice NullPointerException

    It's called "yellow".

  • (cs) in reply to phelyan

    Ahhh, so the Boolean Object does not default to "false" like the primitive...Why would one use the object, instead of the primitive?

  • MWTJ (unregistered)

    Dude! This is so Zen-like that there is nothing that can be said about the code itself.

  • (cs) in reply to samuraiCyborg

    samuraiCyborg:
    Ahhh, so the Boolean Object does not default to "false" like the primitive...Why would one use the object, instead of the primitive?

    Several reasons. Primitive wrappers are immutable, java collections cannot store primitives*, and wrappers extend Object, so can be treated and passed around as such. Also, the wrapper classes provide methods to parse Strings into their respective types.

    <FONT size=2>*the autoboxing of the new collections silently wraps the primitive and then adds it to the collection.</FONT>

  • (cs) in reply to phelyan

    Bugger... that bottom bit was supposed to be smaller, not larger... WTF richtext fields...

  • Dave (unregistered)

    I'm.... speechless.

  • (cs)

    That's pretty funny ... stupid ... but funny.

  • Golly (unregistered) in reply to Maurits

    One more flaw that no one has mentioned yet:
    Yeah, the only reason someone would use the Boolean object instead of a primative boolean in java, is it you want the object to be nullable. This guy's checkFalse function is that it will throw a NPE if the argument is null.

  • Robert (unregistered) in reply to Mung Kee

    I think Java encourages bad programming practices. I'm finding it harder and harder to hire qualified folks who were raised on it.

  • (cs) in reply to Robert

    Anonymous:
    I think Java encourages bad programming practices. I'm finding it harder and harder to hire qualified folks who were raised on it.

    I don't think Java encourages bad practices, I think the problem is that it is an easy language to learn, it's relatively young, and few people are 'raised on it' yet. It's more forgiving than other languages, making it easier to learn and easier to get away with bad code. It's a two edged sword, but the fact that it doesn't discourage bad practices doesn't mean it encourages it. Managers who can't (or can't be bothered to) manage their staff encourage bad practice.

    I've seen some bad developers in my time and 2/3rds of them were not bad at Java, or bad at programming (sure, I've seen some howlers as well), but had come fresh from university or were self-taught and had no commercial experience. Where I see developers struggle is not the code, it's understanding what the code is supposed to do. Too many programmers are smug gits that look down on their customers and don't give a flying about the finished product and its uses.

  • (cs)

    Somewhere, someone, assuming this isnt a sham...was paid to write this..will someone tell me: how well must one know Java to get a job programming Java?

  • (cs) in reply to samuraiCyborg

    samuraiCyborg:
    Somewhere, someone, assuming this isnt a sham...was paid to write this..will someone tell me: how well must one know Java to get a job programming Java?

    1 year experience with java will get you a job worth 23,000 pounds/year in London, UK. For reference, that's about the same a Head Chef in a restaurant will get.

  • (cs)

    Ok, boys and girls, I have another way they could have implemented this:

    static Set trueSet;
    static Set falseSet;
    static {
        Set s = new HashSet(1);
        s.add(Boolean.TRUE);
        trueSet = Collections.unmodifiableSet(s);
        s = new HashSet(1);
        s.add(Boolean.FALSE);
        falseSet = Collections.unmodifiableSet(s);
    }

    public boolean checkFalse(Boolean bool) {
        if(trueSet.contains(bool)) return Boolean.TRUE.booleanValue();
        if(falseSet.contains(bool)) return Boolean.FALSE.booleanValue();
        // otherwise the universe is collapsing!
        throw new IllegalStateException("The universe is collapsing!");
    }

    What do you think?

  • (cs) in reply to phelyan

    1 year experience in Java, academically or professionally?

  • (cs)

    That's just a load of bool!

  • (cs) in reply to samuraiCyborg

    Professionally. Hard experience counts a lot more in the UK. 3-4 years commercial java experience gets you a decent job, even if you have no degree. Take it from an old web monkey like myself.

  • (cs)

    mm maybe he thought that Boolean would be expanded with 'OK', 'Cancel' and 'Abort', 'Rety', 'Fail' [:D]

    but still that wouldn't explain the return [^o)].

  • Z (unregistered) in reply to samuraiCyborg
    samuraiCyborg:
    Are there websites that offer examples of really well-written code?


    You could check out www.lambda-the-ultimate.org. Although it isn't about
    well-written code per se, there are often discussions about how to express
    something in a clean manner.

    The site is good to read even if one isn't interested specifically in
    non mainstream languages, just for the perspective.
  • BogusDude (unregistered) in reply to foxyshadis
    Anonymous:
    (boolValue == true) was the only way to make the

    The problem is that if (boolValue == true) is bad (at least in C and C++). The reason for this is that in C++, 0 is false and everything else is true. Tecnically, true is "defined" as 1, but 1 isn't the only true value (pun intended).

    Certain C library function (often used from C++ as well) return 0 on failure and non zero on success. Therefore, you never check if (x == true), but rather if (x) or if (x != 0) if you absolutely HAVE to write it out.

  • Dr. Shim (unregistered) in reply to WTFer

    The Daily WTF reminds me how comedic code can be.

  • (cs)

    I think that is a wonderful demonstration of encapsulation - you never know when Boolean will have a third or fourth value and hiding it here allows rest of the code to work without change. [;)]

  • Suomynona (unregistered) in reply to richleick
    richleick:
    Ok, in no way am I trying to justify this,


    Wink wink ...

    richleick:
    Then again, maybe this is just plain crap.


    No, you see, this is just plain crap, your pathetic apologies notwithstanding. As has already been pointed out, this function is bool.booleanValue() rewritten in a thoroughly WTFish way, and even the name is a WTF, since this function does not check whether its parameter is false. May I point out that this method should have been static, too?

    I'm always amazed at the amount of nonsense some bleeding-heart coders will spout to justify the most obvious and inexcusable WTFs. Why can't you just acknowledge that there are idiots who write highly idiotic code for no reason whatsoever?

  • (cs) in reply to travisowens
    travisowens:

    But I have created super simple methods such as <font face="Courier New">IsNullOrEmpty()</font> because calling this like   <font face="Courier New">if (IsNullOrEmpty(x))</font>  is much more readable than   <font face="Courier New">if (x == null or x == "")</font>



    That's idiotic!  Whomever in the universe that cannot read if (x == null or x == "") does not merit even looking at the code, much less mantain it.

    What, are we writing code for morons now?  Code should be legible, yes -- but legible to PROGRAMMERS.  There should be some sort of skill or education requirements regarding the platform for anybody to work on it.

        -dZ.

  • (cs) in reply to phelyan
    phelyan:

    Anonymous:
    I think Java encourages bad programming practices. I'm finding it harder and harder to hire qualified folks who were raised on it.

    I don't think Java encourages bad practices, I think the problem is that it is an easy language to learn, it's relatively young, and few people are 'raised on it' yet. It's more forgiving than other languages, making it easier to learn and easier to get away with bad code. It's a two edged sword, but the fact that it doesn't discourage bad practices doesn't mean it encourages it. Managers who can't (or can't be bothered to) manage their staff encourage bad practice.

    I've seen some bad developers in my time and 2/3rds of them were not bad at Java, or bad at programming (sure, I've seen some howlers as well), but had come fresh from university or were self-taught and had no commercial experience. Where I see developers struggle is not the code, it's understanding what the code is supposed to do. Too many programmers are smug gits that look down on their customers and don't give a flying about the finished product and its uses.



    Ha ha ha! Funny!  You misspelled VisualBasic...!

        dZ.

  • mwinmwin (unregistered) in reply to Matt

    you might bump into a null value, dude !

    Not that this WTF is any null-safer, though :^)

  • (cs) in reply to DZ-Jay

    s/Java/$random_programming_language/g

  • lhyr le t&#233;n&#233;breux (unregistered) in reply to mwinmwin

    i think it's just a joke. No one with a little bit experience in IT development could write such a function. And somebody who had one year XP in maths or electronic know what booleans are. So i don't think this post is really serious.

  • (cs) in reply to DZ-Jay

    Well, perhaps by writing the function you could at least encapsulate the fact that it should be

    (x == null || "".equals(x)) in Java.

  • (cs) in reply to DZ-Jay
    DZ-Jay:
    travisowens:

    But I have created super simple methods such as <font face="Courier New">IsNullOrEmpty()</font> because calling this like   <font face="Courier New">if (IsNullOrEmpty(x))</font>  is much more readable than   <font face="Courier New">if (x == null or x == "")</font>



    That's idiotic!  Whomever in the universe that cannot read if (x == null or x == "") does not merit even looking at the code, much less mantain it.

    What, are we writing code for morons now?  Code should be legible, yes -- but legible to PROGRAMMERS.  There should be some sort of skill or education requirements regarding the platform for anybody to work on it.

        -dZ.



    Well, perhaps by writing the function you could at least encapsulate the fact that it should be

    (x == null || "".equals(x)) in Java.

    														</td></tr></tbody></table></td></tr></tbody>
    

  • (cs)

    I agree with an eariler poster... this isn't a WTF it is an OMG!!!!

    As in Oh My God, it burns, it burns lol!

  • Anonymous coward (unregistered) in reply to Mung Kee
    Mung Kee:
    so there is no "true" or "false" in M$ land?

    You've already acknowledged your mistake, but I would just like to rehash it. Mainly because you said "M$" in your first post that you rushed out in your hurry to bash Microsoft. Why doesn't "$un" get bashed now? How come I never see "The real WTF is that someone used $un's programming language!"?

    P.S. I can't stand it when people type "M$", "New York Yankee$", etc.

  • e (unregistered) in reply to curtisk

    curtisk:

    Just noticed that myself....LOL, and yeah its definitely not C# they use "bool" instead of "Boolean"

    For the record - Boolean is equivalent to bool in C#, just as Single is equivalent to float, since they are the canonical .NET class names (also valid in VB.NET, etc.).

  • (cs) in reply to Anonymous coward
    Anonymous:
    Mung Kee:
    so there is no "true" or "false" in M$ land?
    You've already acknowledged your mistake, but I would just like to rehash it. Mainly because you said "M$" in your first post that you rushed out in your hurry to bash Microsoft. Why doesn't "$un" get bashed now? How come I never see "The real WTF is that someone used $un's programming language!"? P.S. I can't stand it when people type "M$", "New York Yankee$", etc.


    Yeah, I managed to restrain myself earlier, but...

    Do you guys who write M$ or Micro$oft still think you're witty?  It's been done, pick up something else.  All other arguments against Microsoft aside, come up with some original material.
  • (cs) in reply to travisowens
    travisowens:

    While I will admit this code is slightly wierd, I will defend the reasoning behind it. I can tell you now this was done purely for human legibility of code.  While I haven't done something this simple of a check, I've often created methods soley for the reason of more readable code.

    But I have created super simple methods such as <font face="Courier New">IsNullOrEmpty()</font> because calling this like   <font face="Courier New">if (IsNullOrEmpty(x))</font>  is much more readable than   <font face="Courier New">if (x == null or x == "")</font>

    But I think somebody took this concept way to far because he already has a boolean to check against.

    I try to make my code as english readable as possibly, call it dumbing it down, but even a non coder can understand the basics of my OOP code.



    I'm still in pain when I consider Visceral Baysuck, where a glance at the documentation shows an IsEmpty(), IsMissing(), and IsNull(),  and then the Nz() function in Access, all of which provide, shall we say, "entertaining" semantics as you WTF your way through an task.
    All I can say, man, is: pray for JavaScript.
  • Hank Miller (unregistered) in reply to samuraiCyborg
    samuraiCyborg:
    Somewhere, someone, assuming this isnt a sham...was paid to write this..will someone tell me: how well must one know Java to get a job programming Java?


    Last I was interested in a Java position you needed at least 5 years of Java.  This was in 1997 , so you would have to be a Sun employee to have a shot at that.  (Java 1.0 was announced in 1995)

    Last time I was looking for a job, were no Java only jobs, only 10 years Java, 5 years .Net.   This was in 2003.  

    Of course you know what this means: the only people with Java or .Net jobs are people who can lie with a straight face and convince the PHB that they are telling the truth. 
  • Stevie (unregistered)

    Here's the best bit,

    checkFalse(null);


  • (cs) in reply to DZ-Jay
    DZ-Jay:
    travisowens:

    But I have created super simple methods such as <font face="Courier New">IsNullOrEmpty()</font> because calling this like   <font face="Courier New">if (IsNullOrEmpty(x))</font>  is much more readable than   <font face="Courier New">if (x == null or x == "")</font>



    That's idiotic!  Whomever in the universe that cannot read if (x == null or x == "") does not merit even looking at the code, much less mantain it.

    What, are we writing code for morons now?  Code should be legible, yes -- but legible to PROGRAMMERS.  There should be some sort of skill or education requirements regarding the platform for anybody to work on it.

        -dZ.



    There should be, yes, but there often isn't.  Just last week one of my coworkers, who has plenty of experience working with our company's data but absolutely no programming experience whatsoever, was given the task of maintaining a VB .Net application.  He's never, ever, touched anything resembling VB, VB .NET or any other programming language for that matter.  My mind, it boggles!
  • (cs) in reply to Maurits

    What kills me is, this clown actually calls Boolean.booleanValue() in this crap method.  He obviously knows it exists.  If he called it in the first god damn place he wouldn't be the punchline right now.

  • (cs) in reply to Golly
    Anonymous:

    Yeah, the only reason someone would use the Boolean object instead of a primative boolean in java, is it you want the object to be nullable.


    How about Serialization?  Also, certain forms of RMI require that you pass Objects and not primitives.
  • (cs) in reply to Anonymous coward
    Anonymous:
    Mung Kee:
    so there is no "true" or "false" in M$ land?
    You've already acknowledged your mistake, but I would just like to rehash it. Mainly because you said "M$" in your first post that you rushed out in your hurry to bash Microsoft. Why doesn't "$un" get bashed now? How come I never see "The real WTF is that someone used $un's programming language!"? P.S. I can't stand it when people type "M$", "New York Yankee$", etc.


    While I fully realize that it was/is a derogatory term for Microsoft, in this case, I assure you, it was merely shorthand.
  • (cs)

    I think the real WTF here is that there are 90 posts and nobody's recommended JavaScript or XML.

  • (cs) in reply to FrostCat

    FrostCat:
    I think the real WTF here is that there are 90 posts and nobody's recommended JavaScript or XML.

    All I can say, man, is: pray for JavaScript.

     

    Ok, the REAL real WTF is that I actually searched the page for JavaScript and XML before making my post, and it didn't find either term.

     

  • (cs) in reply to e
    Anonymous:

    For the record - Boolean is equivalent to bool in C#, just as Single is equivalent to float, since they are the canonical .NET class names (also valid in VB.NET, etc.).



    I've gotten into the habit of using the System datatypes (System.Int32, System.Boolean) in my code. I was never sure why until I reviewed some old VB code and was reminded of the fabulous 16-bit Integer datatype.

    There are no primitives in .NET, and I don't really miss them.
  • Greg Helton (unregistered) in reply to Ytram

    The language is Java.  The developer is VB.

  • Davey (unregistered)

    Alex Papadimoulis:

    <FONT color=#000099>public boolean</FONT> checkFalse(<FONT color=#000099>Boolean</FONT> bool)
    {
      <FONT color=#000099>if</FONT> (bool.booleanValue() == <FONT color=#000099>Boolean</FONT>.<FONT color=#000099>FALSE</FONT>.booleanValue())
      {
        <FONT color=#000099>return</FONT> <FONT color=#000099>Boolean</FONT>.<FONT color=#000099>FALSE</FONT>.booleanValue();
      }
      <FONT color=#000099>else</FONT>
      {
        <FONT color=#000099>return</FONT> <FONT color=#000099>Boolean</FONT>.<FONT color=#000099>TRUE</FONT>.booleanValue();
      }
    }

    </FONT>

    Ah, well in Java 1.5, there's autoboxing, so you can have something like:

    @SuppressWarningsAutoboxing

    ....

    Boolean test = new Boolean(true);

    if(test)

    .....

     

    But really, I think having primative and object wrappers of the same data types is a huge WTF in java.

  • (cs) in reply to Robert

    Anonymous:
    I think Java encourages bad programming practices. I'm finding it harder and harder to hire qualified folks who were raised on it.

    My experience is that VB, VB-esque languages, and Perl encourage bad practices.  When Java was new, it had a whole philosophy (religion) built-up around it that were essentially bad practices.  Perhaps that's what you are referring to.  All of these stupid ideas are wholly discredited and largely abandonded but you still see some clueless people reading the old books and holding onto these ideas.  There's a couple keynotes from Java One this year that talk about them that you can watch on the ServerSide.  In particular Rod Johnson's "Why J2EE projects fail"

  • (cs) in reply to Davey
    Anonymous:

    Ah, well in Java 1.5, there's autoboxing, so you can have something like:

    @SuppressWarningsAutoboxing

    ....

    Boolean test = new Boolean(true);

    if(test)

    .....

     

    But really, I think having primative and object wrappers of the same data types is a huge WTF in java.

    You could even just do this:

    Boolean test = true;

    if(test);

    They should have just made primitives work the way that arrays work i.e. you could treat them as if they were Objects i.e. all the base Object class methods are defined for the primitive types but there's actually no Object involved.  It would have saved everyone a lot of pain and suffering.

  • (cs) in reply to phelyan
    phelyan:

    samuraiCyborg:
    Ahhh, so the Boolean Object does not default to "false" like the primitive...Why would one use the object, instead of the primitive?

    Several reasons. Primitive wrappers are immutable

    I don't see how this is a reason to use wrapper types.  It doesn't give any extra modifcation protection.

  • Andrew (unregistered) in reply to Robert

    Anonymous:
    I think Java encourages bad programming practices. I'm finding it harder and harder to hire qualified folks who were raised on it.

     

    No, its not that.  CS programs have dumbed down.  Eight years ago, I asked a professor, "When is this going to get hard," in reference to CS202 and CS203.  The answer was that they had started making it intentionally easier so less people would drop out.  The attrition rate from CS201 to CS203 was about 80%.  Because its either Java or VB in most CS programs now, you're seeing a lot of people who would have been weeded out get degrees instead.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

Leave a comment on “A False Detector”

Log In or post as a guest

Replying to comment #:

« Return to Article