- 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
Ooh, first post I think.
Anyway, none of these are that WTF, more of momentary lack of common sense, and nothing that usually effects a project too badly.
Admin
I have used logic like this from time to time. It's useful when you are doing crazy matrix stuff, or drawing operations. Reminds me of ActionScript.
See you in the bar,
Ribbly
Admin
great..!
Admin
very cute :)
Admin
Admin
Admin
Why not just skip the check and set
nextIndex = currIndex?
Isn't that the final result regardless?
Admin
Bingo. That's the WTF.
Admin
if(eyes || goggles) {
DoNothing();
}
Admin
I can think of some reasons something of this nature might be written.
1) It's a left-over from debugging. Set a hardware breakpoint on a write to the address of nextIndex and the programmer put the above code in to avoid red herrings. It would be very easy to forget to remove the conditional afterwards.
2) There's something about nextIndex that makes write operations to it expensive. It's really something other than just a simple variable that it looks like.
Admin
Admin
Ah, they must have been trying to write:
Admin
Not necessarily. The context of this code block is inside a loop, where calculations are performed and different code paths can be taken.
You might have a scenario where you only move to the next index when certain conditions are met, otherwise you continue with the loop using the index you've been using.
Although on closer inspection it looks like the writer is trying to determine when to reset the "next" index to the "current" index. Obviously without more code, I don't know shit. But I would be open-minded to see how it would work if more code was supplied.
See you in the bar,
Ribbly
Admin
retVal = retVal || false
<FONT color=#000000>???... </FONT><FONT color=#000000>Wow! a WTF inside a WTF. </FONT><FONT color=#000000>Truly amazing.</FONT>
<FONT color=#000000>Watch out folks, this stuff could render a man idempotent. [H]</FONT>
Admin
here is a piece of code along those lines that i've found commented out in an app that I was maintaining:
//if(!strFalse.isdbNull()!=false)
//{
//strResult=strFalse.ToString();
//}
i couldn't find the context or meaning either because none of those strings are present anywhere else in the app code.
maybe it was some previous maintenance's cruel joke or something
Admin
//remove this reply
Admin
Gene Wirchenko, where are you?
I miss you.
Sincerely,
gwfc
Admin
if (toB || !toB)
{
return that_is_the_question();
}
Admin
Is it just me or is anyone else thinking that those things that look like variables could be properties with side effects, that the app could fail if we nuke the apparently redundant stuff, and so a developer might just leave that stuff there on the if it ain't broke don't fix it principle.
with the introduction of properties, you can never understand a snippet of code any more because it just might be hiding other complexities. You can no longer look at a snippet and confidently say you know for sure it does not call something and thus understand it.
Admin
Reminds me of something I wrote once:
std::string role; // assume this is assigned somewhere else
...
if ( role != "something" || role != "something else" )
{
return;
}
// wtf isn't anything here being executed??
...
--
Bill C++
Admin
I believe this is more correct
if(eyes && goggles) {
DoNothing();
}
Admin
Uhhh The SAME code path will be taken immediately following this statement, whether you are in a loop, outside of a loop, or in a bar.
The only real reason to do this code is if your = operator is overloaded and does some weird stuff, or it is very expensive to do a write. Save the few cycles to do the comparison and just set the value.
Admin
Perl is your language of choice here:
<FONT face="Courier New">my $eyes;</FONT>
<FONT face="Courier New">$the_goggles->do_nothing();</FONT>
Admin
As we learned yesterday a bool has a third state, not true or false, so this is a perfectly legitimate statement. Therefore I'm certain the code edited out handles the situation when the process is unsure if the connection is open.
Admin
Ooooo. A brillant way to execute code the instant the actionFlag changes from 0 to 1! Who needs events or callbacks?
--Rank
Admin
You're both wrong:
if(goggles && DoNothing())
{
MyEyes.EyeState = EyeState.Burning;
}
Admin
What? no isTrue functions today?[:'(]
Admin
Monday:
<FONT face="Courier New"><FONT color=#006400>//Remove the following line:</FONT>
currentUserId = currentUserId</FONT>;
Tuesday:
<FONT face="Courier New" color=#006400>//Remove the following line:</FONT>
Wednesday:
<FONT face="Courier New" color=#006400>//Remove the following comment:
//Remove the following line:</FONT>
Thursday:
<FONT face="Courier New" color=#006400>//Remove the following comment:</FONT>
Friday:
<FONT face="Courier New" color=#006400>//Remove this and the following comment:
//Remove the following comment:</FONT>
Friday night:
<FONT face="Courier New" color=#006400>//Remove and the following comment:
</FONT>
--Rank
Admin
Many of these can be explained by poorly executed operator overloads :P
Admin
I never get sick of this kind of stupid.
Admin
hey, but eyes must include left and right eye, they are different you know
if(Goggles!=null){
Goggles.Lens[Left].Shatter();
if(MyEyes[Left]!=null)
MyEyes[Left].State=EyeState.Burning;
Goggles.Lens[Right].Shatter();
if(MyEyes[Right]!=null)
MyEyes[Right].State=EyeState.Burning;
}else{
delete(MyEyes);
}
of course this doesn't cover cases of glass eyes ,contact lenses, and direct brain damage in case of no eyes and no goggles
Admin
What if you wanted to do something only if the value was different?
static unsigned int nOldState = 0;
if(nOldState != GetState())
{
nOldState = GetState();
Update();
}
OtherFunction();
In this case you wouldn't want Update() to be called unless the state was different.
Admin
Admin
The real WTF is that these aren't bitwise operators.
Admin
Disclaimer: I have never programmed C#
Doesn't C# have "properties". If so, it is possible that actionFlag actually triggers a "hidden" property method that could be doing lots of stuff, including changing the value the next time it is accessed?
Admin
There could also be some object stuff going on there, there are some languages (.NET for example) where there can be very little difference between an object and a variable (let me correct myself, there is no difference in .NET, everything is an object untill you get down to the very core of the language... which I never plan on doing) This code can easily compare two objects and if they are not the same then copy one object to the other, in that copy function there could be a ton of stuff going on whereas very little would go on in the compare... either way it would be nice to more about what's going on around this bit of code.
However it's more likely that they are just doing this for complexity/confusion sake.
Erik of Ekedahl
Admin
That's called coupling. Maybe you should post it here.
Admin
if(language == english)
{
st = "whose";
}
else
{
//st = "who's";
st = "whose";
}
</irony>
Admin
This comes from the human thinking "doing something" (like an assignment) is more expensive than "looking at something".
Probably a breakpoint line for the debugger.
If this is C++ and actionFlag is of some obscure class (which overwrites == in a strange way), it might actually evaluate to true.
Admin
<font size="1">
<font size="2">Sorry, you didn't pray hard enough. You have been pwned.
Sincerely,
The Lord
</font></font>
Admin
Yes, C# has properties, but the naming convention when writing them is to capitalize the first letter as well. They may still be properties, but they don't LOOK like it.
Admin
This is obvious- he's an electrical engineer who wants to make this logic edge triggered. Its a huge advance in CS.
(TO those with no electircal background- to do clock based circuits, you actually do things like (clock NOR (NOT clock)) to detect when a wire signal changes- since the extra NOT gate will take a non-zero time to complete, that result will actually be 1 for a fraction of a nanosecond when clock goes from 1 to 0).
Admin
I've made that mistake lots and felt really dumb each time. Now I just test the stuff before checking in so I minimize the risk of someone else noticing the error before I fix it. Though hardest part about that bug for me is trying to convince someone else that they should be using && instead of ||. Showing someone DeMorgan's laws doesn't usually help the situation. Maybe I should ask people to debug that thing as part of an interview...
Admin
for each eye { goggle = .null. }
Admin
I just laughed harder at that Simpson's quote than I did at any of the code examples.
Admin
I imagine at one point there was more code there, and that step was to make sure it was iterating correctly though a big pile of values.
Every now and again I end up setting up an "if(managementHasMadeUpItsMind){}" block to cut out a big chunk of control logic that someone has decided they don't need, but which I privately believe they'll be asking me to implement again in a month or two, which leaves "wtf?" moments lying around in my code, but saves me a lot of implementation time in the future. Just set managementHasMadeUpItsMind = True; and you're good to go surf the web for 5 days while you're "implementing" logic that you knew they didn't want removed in the first place.
Admin
Admin
This reminds me of a couple of almost-wtf's I found in a script a little while ago. It's easy to understand how these things happen as code is revised, but basically it looked like this:
if ((a and b) or (b)) { do_stuff(); }
where a and b were actually pretty long conditions. Then later there was this:
if (a and !b) { // lots of stuff if (b) { // lots more stuff } }
A different a and b, but still lengthy statements (and b was not recalculated in any way).
Admin
Bwahaha.
Reminds me of my trash company. Do you know how HARD it is to throw away a trash can??
Last week after they emptied our trash, one of the cans got blown out into the road (big squarish green plastic can with wheels). A car hit it and destroyed it. I mean, destroyed--wheels gone, bottom end flattened like a pancake. The top is still squarish, so it might hold a small bit of trash if I propped it up against the house or something, but anyone who sees it is going to say "jeez, what happened to your trash can?".
So this week, I put the good can out at the curb, and next to it we were throwing away a big empty box. So I put a bag or two of trash in the box, then I cram the mangled trash can upside-down inside the box. The message is obvious, right? "This is trash. Please haul it away."
Nope. They pulled the mangled trash can out of the top of the empty box, and left it on the curb.
I know if I leave a sign that says "please take this", they'll just take the note :)
Admin
Funny, I always thought "eyes + goggles == eyes" was more closer to the original quote...