Comment On Boolean Illogic

One of the great things about Boolean logic is its simplicity. At the most basic level, there's simply TRUE and FALSE with AND, OR, and NOT. It takes a lot of work to overcomplicate such a simple system, yet "certain" developers seem to find such over-complication second nature. Take E.H.'s colleague, for example. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: Boolean Illogic

2010-08-11 09:01 • by The Nerve (unregistered)
Triple-negative logic FTW!

Re: Boolean Illogic

2010-08-11 09:02 • by Morrell (unregistered)
oh dear god

my answer is Maybe

Re: Boolean Illogic

2010-08-11 09:03 • by Alargule (unregistered)
^^ That is not not not not not not !=true=false

Re: Boolean Illogic

2010-08-11 09:03 • by Gram ma (unregistered)
Steven:
FIRST


fail.

Re: Boolean Illogic

2010-08-11 09:03 • by TheRealWTF (unregistered)
The Real WTF is that Alex totally missed out FILE_NOT_FOUND.

Re: Boolean Illogic

2010-08-11 09:04 • by Cbuttius
More importantly do we skip validation if fileNotFound occurs?

Re: Boolean Illogic

2010-08-11 09:05 • by SR (unregistered)

if (comment.compareTo (Comment.FRIST)) {
return Boolean.FILE_NOT_FOUND;
}


Or something

Re: Boolean Illogic

2010-08-11 09:06 • by BenHead (unregistered)
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)
317268 in reply to 317267
tri-state boolean... now that's nuts :)

Re: Boolean Illogic

2010-08-11 09:08 • by Crabs (unregistered)
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.

Re: Boolean Illogic

2010-08-11 09:09 • by Sigh (unregistered)
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)
317272 in reply to 317264
TheRealWTF:
The Real WTF is that Alex totally missed out FILE_NOT_FOUND.


and what about XOR

Re: Boolean Illogic

2010-08-11 09:12 • by Ah yes (unregistered)
The best part about the code is it will be easy to add the conditionals for less than and greater than as well.

Re: Boolean Illogic

2010-08-11 09:13 • by AR (unregistered)
317274 in reply to 317272
NOT

Re: Boolean Illogic

2010-08-11 09:14 • by Jakob H. Poulsen (unregistered)
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.

Re: Boolean Illogic

2010-08-11 09:15 • by Cbuttius
317276 in reply to 317259
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.

Re: Boolean Illogic

2010-08-11 09:16 • by brazzy
317277 in reply to 317271
Sigh:
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.

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.

Re: Boolean Illogic

2010-08-11 09:17 • by bertram
317278 in reply to 317268
Morrell:
tri-state boolean... now that's nuts :)


You must be new here ;)

Re: Boolean Illogic

2010-08-11 09:17 • by Steve The Cynic
This code is why E.H. has to have a desk in his workplace...

To bounce his colleague's head off of, duh.

Re: Boolean Illogic

2010-08-11 09:17 • by caffeine (unregistered)
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.

Re: Boolean Illogic

2010-08-11 09:18 • by bertram
317281 in reply to 317271
Sigh:
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.


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.

Re: Boolean Illogic

2010-08-11 09:19 • by Someone You Know
Alex Papadimoulis:
At the most basic level, there's simply TRUE and FALSE with AND, OR, and NOT.


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".

Re: Boolean Illogic

2010-08-11 09:19 • by frits
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)
317285 in reply to 317264
TheRealWTF:
The Real WTF is that Alex totally missed out FILE_NOT_FOUND.
Or Fish

(see http://thedailywtf.com/Articles/Go-Fish.aspx as the spam filter thinks a link to another WTF article is spam)

Re: Boolean Illogic

2010-08-11 09:21 • by Cbuttius
317286 in reply to 317275
Jakob H. Poulsen:
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.


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)
317287 in reply to 317275
Jakob H. Poulsen:
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.


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.

Re: Boolean Illogic

2010-08-11 09:23 • by da Doctah
317288 in reply to 317283
Someone You Know:
Alex Papadimoulis:
At the most basic level, there's simply TRUE and FALSE with AND, OR, and NOT.


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".


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)
317290 in reply to 317284
frits:
This is only a WTF if statusIsNotValid is a boolean. If it is some other type, this really isn't much of a WTF.


Troll or idiot?

Re: Boolean Illogic

2010-08-11 09:26 • by Cbuttius
317292 in reply to 317281
bertram:
Sigh:
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.


There is absolutely nothing about that code snippet that guarantees that it's Java. But thanks for playing.


Boolean.FALSE is defined in Java.

Re: Boolean Illogic

2010-08-11 09:26 • by Drew (unregistered)
317293 in reply to 317286
Cbuttius:
We could do skipValidation &&= predicate though.


What language has that operator?

Re: Boolean Illogic

2010-08-11 09:29 • by Sigh (unregistered)
317294 in reply to 317281
bertram:
Sigh:
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.


There is absolutely nothing about that code snippet that guarantees that it's Java. But thanks for playing.


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.

Re: Boolean Illogic

2010-08-11 09:29 • by Darth Boolean (unregistered)
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)
317296 in reply to 317278
bertram:
Morrell:
tri-state boolean... now that's nuts :)


You must be new here ;)


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. ;)

Re: Boolean Illogic

2010-08-11 09:34 • by Drew (unregistered)
317297 in reply to 317271
Sigh:
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.


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)
317298 in reply to 317286
1. Point well taken.

2. Ever since Java 5 we have auto(un)boxing. The original code could be older than that though.

Re: Boolean Illogic

2010-08-11 09:37 • by frits
317299 in reply to 317290
Matt K:
frits:
This is only a WTF if statusIsNotValid is a boolean. If it is some other type, this really isn't much of a WTF.


Troll or idiot?


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.

Re: Boolean Illogic

2010-08-11 09:42 • by Matt (unregistered)
I can't not misunderstand what he was not trying to unachieve.

Re: Boolean Illogic

2010-08-11 09:42 • by Sigh (unregistered)
317301 in reply to 317297
Drew:
Sigh:
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.


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? :)


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)
317302 in reply to 317275
Jakob H. Poulsen:
E.H.'s colleague should have his programming privileges revoked for messing with people's head like that!

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)
317303 in reply to 317300
Matt:
I can't not misunderstand what he was not trying to unachieve.

+1, or actually -(-(-(-(1))))

Re: Boolean Illogic

2010-08-11 09:48 • by Rootbeer

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)
317305 in reply to 317300
Matt:
I can't not misunderstand what he was not trying to unachieve.


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)
317306 in reply to 317294
Sigh:
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.

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.

Re: Boolean Illogic

2010-08-11 09:57 • by ipeet
317307 in reply to 317299
frits:
Matt K:
frits:
This is only a WTF if statusIsNotValid is a boolean. If it is some other type, this really isn't much of a WTF.


Troll or idiot?


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.


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.

Re: Boolean Illogic

2010-08-11 10:01 • by Mcoder
317309 in reply to 317276
Cbuttius:
Oh well, C++ is so much simpler sometimes with operator overloading.


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).

Re: Boolean Illogic

2010-08-11 10:04 • by frits
317310 in reply to 317307
ipeet:
frits:
Matt K:
frits:
This is only a WTF if statusIsNotValid is a boolean. If it is some other type, this really isn't much of a WTF.


Troll or idiot?


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.


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.


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.

Re: Boolean Illogic

2010-08-11 10:06 • by lupo
317311 in reply to 317306
Ouch!:
But it's very unlikely to be anything else.

I think it's more of very likely to be nothing else

Re: Boolean Illogic

2010-08-11 10:08 • by Ken B. (unregistered)
317312 in reply to 317272
Robert:
TheRealWTF:
The Real WTF is that Alex totally missed out FILE_NOT_FOUND.
and what about XOR
That's just "or and not and".

a XOR b == (a OR b) AND NOT (a AND b)

Re: Boolean Illogic

2010-08-11 10:08 • by Mason Wheeler
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."
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment