| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Next » |
|
Triple-negative logic FTW!
|
|
oh dear god
my answer is Maybe |
|
^^ That is not not not not not not !=true=false
|
fail. |
|
The Real WTF is that Alex totally missed out FILE_NOT_FOUND.
|
|
More importantly do we skip validation if fileNotFound occurs?
|
Or something |
|
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. |
Re: Boolean Illogic
2010-08-11 09:07
•
by
Morrell
(unregistered)
|
|
tri-state boolean... now that's nuts :)
|
|
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. |
|
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. |
Re: Boolean Illogic
2010-08-11 09:10
•
by
Robert
(unregistered)
|
and what about XOR |
|
The best part about the code is it will be easy to add the conditionals for less than and greater than as well.
|
|
NOT
|
|
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. |
|
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. |
Because using any language other than Java makes people magically unable to code crap... If you think Java is the problem here, TRWTF is you. |
You must be new here ;) |
|
This code is why E.H. has to have a desk in his workplace...
To bounce his colleague's head off of, duh. |
|
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. |
There is absolutely nothing about that code snippet that guarantees that it's Java. But thanks for playing. |
Re: Boolean Illogic
2010-08-11 09:18
•
by
Someone who can't be bothered to login from work
(unregistered)
|
|
At a basic level you could just have NAND and NOR, because they're functionally complete.
|
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". |
|
This is only a WTF if statusIsNotValid is a boolean. If it is some other type, this really isn't much of a WTF.
|
Re: Boolean Illogic
2010-08-11 09:21
•
by
monkeyPushButton
(unregistered)
|
Or Fish (see http://thedailywtf.com/Articles/Go-Fish.aspx as the spam filter thinks a link to another WTF article is spam) |
1. 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. 2. compareTo is a class method, and you can't just put if round your object. This isn't C++ with operator overloading. |
Re: Boolean Illogic
2010-08-11 09:23
•
by
highphilosopher
(unregistered)
|
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. |
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. |
Re: Boolean Illogic
2010-08-11 09:25
•
by
Matt K
(unregistered)
|
Troll or idiot? |
Boolean.FALSE is defined in Java. |
What language has that operator? |
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. |
|
I have validated your logic! Pray I don't validate it any further.
|
Re: Boolean Illogic
2010-08-11 09:32
•
by
Gozer Gozerian
(unregistered)
|
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. ;) |
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? :) |
Re: Boolean Illogic
2010-08-11 09:34
•
by
Jakob H. Poulsen
(unregistered)
|
|
1. Point well taken.
2. Ever since Java 5 we have auto(un)boxing. The original code could be older than that though. |
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. |
|
I can't not misunderstand what he was not trying to unachieve.
|
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. |
Re: Boolean Illogic
2010-08-11 09:43
•
by
Most Pessimum
(unregistered)
|
QFT... In Programming 101 they taught us to always use "positive names" for boolean variables, i.e. statusValid and doValidation, as opposed to statusIsNotValid and skipValidation. Mostly because it avoids writing a complete and utter abortion of code, like what we see here. |
Re: Boolean Illogic
2010-08-11 09:45
•
by
vulputate
(unregistered)
|
+1, or actually -(-(-(-(1)))) |
|
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. |
Re: Boolean Illogic
2010-08-11 09:50
•
by
DonaldK
(unregistered)
|
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. |
Re: Boolean Illogic
2010-08-11 09:51
•
by
Ouch!
(unregistered)
|
Still doesn't prove it, with appropriate definitions in scope, it could be C, C++, C# and probably a fistful of languages more. So technically bertram is right, nothing guarantees it's Java. But it's very unlikely to be anything else. |
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. |
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). |
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. |
I think it's more of very likely to be nothing else |
Re: Boolean Illogic
2010-08-11 10:08
•
by
Ken B.
(unregistered)
|
That's just "or and not and". a XOR b == (a OR b) AND NOT (a AND b) |
|
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." |
| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Next » |