- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Triple-negative logic FTW!
Admin
oh dear god
my answer is Maybe
Admin
^^ That is not not not not not not !=true=false
Admin
fail.
Admin
The Real WTF is that Alex totally missed out FILE_NOT_FOUND.
Admin
More importantly do we skip validation if fileNotFound occurs?
Admin
Or something
Admin
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.
Admin
tri-state boolean... now that's nuts :)
Admin
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.
Admin
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.
Admin
and what about XOR
Admin
The best part about the code is it will be easy to add the conditionals for less than and greater than as well.
Admin
NOT
Admin
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.
Admin
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.
Admin
If you think Java is the problem here, TRWTF is you.
Admin
You must be new here ;)
Admin
This code is why E.H. has to have a desk in his workplace...
To bounce his colleague's head off of, duh.
Admin
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.
Admin
There is absolutely nothing about that code snippet that guarantees that it's Java. But thanks for playing.
Admin
At a basic level you could just have NAND and NOR, because they're functionally complete.
Admin
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".
Admin
This is only a WTF if statusIsNotValid is a boolean. If it is some other type, this really isn't much of a WTF.
Admin
(see http://thedailywtf.com/Articles/Go-Fish.aspx as the spam filter thinks a link to another WTF article is spam)
Admin
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.
compareTo is a class method, and you can't just put if round your object. This isn't C++ with operator overloading.
Admin
Ok, but you're still over complicating it...
@#$ck statusIsNotValid, replace it with statusValid, and then...
skipValidation = statusValid
Or better yet, JUST USE THE statusValid! Don't create extra crap.
captcha: eros (as in) -- the eros in this wtf seem fabricated and fake.
Admin
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.
Admin
Troll or idiot?
Admin
Boolean.FALSE is defined in Java.
Admin
What language has that operator?
Admin
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.
Admin
I have validated your logic! Pray I don't validate it any further.
Admin
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. ;)
Admin
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? :)
Admin
Point well taken.
Ever since Java 5 we have auto(un)boxing. The original code could be older than that though.
Admin
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.
Admin
I can't not misunderstand what he was not trying to unachieve.
Admin
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.
Admin
Admin
Admin
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.
Admin
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.
Admin
Admin
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.
Admin
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).
Admin
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.
Admin
Admin
a XOR b == (a OR b) AND NOT (a AND b)
Admin
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."