- 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
The real WTF is that he needed a truth table to figure out that was the same as:
return test;
When you have boolean == boolean ? (boolean == boolean ? boolean : boolean) : (boolean == boolean ? boolean : boolean), then it's a pretty safe bet you're returning a boolean value, like the one you're comparing to true in the first place.
I guess I'm not accounting for FILE_NOT_FOUND in my example though . . .
Admin
The programmer who wrote this was stoned at the time. :)
OK ok.. boolean .. got to return boolean... boolean, right! True or false! Right, true of false... true or false.. OK - if the variable is true.. test it again just to make sure.. If it false on the back up test, return false.. false.. false... oh yeah, it's a boolean. Damn I'm hungry..
Admin
You also don't get it do you. A boolean can only be true or false. A boolean variable can be true false or null, but it should always be safe to assume either true or false when presented with a null. If it can not be safely assumed, then you don't have a boolean, you have a tri-state enumeration. i.e. Shipped variable, if it is null you can safely assume false. Inspected variable, if null assume false. PackageReceived variable, if null assume unknown, this is a third state not handled by a boolean, so you now have an enumeration with three values, do not represent this with a boolean as it can not handle all potential values, as once you have three values, you may find more.
Admin
Even if I can prove that my changes didn't cause the bug (which they almost never have) he would get pissed off and instruct me to not make changes like that without clearing them with him first.
It's just not worth the hassle of being harassed when you're in that situation.
Fortunately, my boss has come to trust me a lot more and I am allowed a lot more leeway now, but most developers without tenure do not have that luxury.
Admin
Could be a race condition from some multithreaded stuff. Two out of three wins!
Admin
Oh man! BURN! Dude! What grade are you in? Can I sit with you at the cool kids table? We can slap high fives later. w00t.
Admin
Admin
A calendar?
Well, "this millennium" implies C99 at least, so why not?
[*] ps: Yes, ok, I have heard of C++ builder :)
Admin
if (test == true) return true; else if (test == false) return false; else return !true && !false;
Admin
Just goes to show there are some really stupid programmers out there. They should be shot. or go into a career that better suites them...like...errr....errr... s**t shovelers or something.
This guy would be off my team in 2 seconds flat with code like that.
Admin
Or maybe the code is in a multi-threaded application and the value of test can then be changed at the last moment...
Still doesn't make sense.
Admin
I suspect that it is less than optimal code left after a risky refactor of some other variable to test or an even more risky search and replace, whereby moving on without review. Let's just assume the change was made and then it passed a unit test. Even extending the benefit of doubt, even if the second nested ternary operation was on another named boolean, return test && other; would have worked.
What I don't get is this... I consider ternary operations, including nested operations, an advanced topic. Normally newbs will us an if-else structure from hell before tempting fate with the ?: operator. I wonder what lead up to this piece?
I wonder if some refactoring utility took a pure boolean related if-then-else tree that only returned values conditionally and created this mess?
I give up, I will go back to working on my program that attempts to understand women.
Admin
Not all comments are worth getting your pantyhose in a twist.
Admin
Well, there's the known knowns, known unknowns and the unknown unknowns !! So maybe he's just being cautions !! Then again, he could be just not very good !!
Admin
This line surely is cool maybe the guy was joking
(take it as the X file new slogan :"I Want to believe")
Admin
Personally I would say that it was deliberate obfuscation in order to cause confusion.
Whoever wrote that algorithm, no matter how stupid it might seem, had extremely good logic processing skills, that's a fact.
Admin
WTF? That makes even less sense! No way would that slow down the CPU enough to let another operation occur. Concurrent thread handling is performed through mutex's and wait events, not boolean logic!
Admin
hahaha! palms face
Quantum computing my arse.