- 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
"You can buy it in any color, as long as it's black." -- Henry Ford
Admin
OnceAndOnlyOnce
DontRepeatYourself
Admin
Having deletes and any new states that may be introduced handled by the default case is a brilliant optimization saving untold slots in the jump table, and is also forward compatible.
Admin
I'm guessing (hoping?) these two code snippets were coded by forward-thinking coders for future enhancements or have had lines of code deleted from them and the switch and if/else statements not removed yet.
Admin
At least the first programmer added comments
//Load Page Data
Admin
Bruhahahahahaha. I love it when I see code like this. It just makes my day. [:D]
Admin
No, it does not beg the question. It raises the question.
Admin
The second example simply covers both conditions: "Y" and Why Not?
Admin
Meh.
I'm betting that this is simply the results of rapid cut'n'paste code stubbing that the developer just hasn't returned to.
Big freaking deal. (Unless of course this is in production-ready code, then shame on the developer)
Admin
This code(found today by a coworker in production code) is (I think the) epitome of code that "does the same thing no matter what," and to really take the cake, that same thing is... NOTHING!
Comments are as found.
Admin
Um, could just be they plan to change the functions later on. Or planned on it and never did.
Admin
It does worse than nothing. It spins in a hard loop forever. But hey, at least it sleeps for what appears to be 5ms before doing so. I assume this is to allow all the other processes to finish up before it goes hog-wild. hehehe
Admin
i am not redundant
i am not redundant
i am not redundant
i am not redundant
i am not redundant
...
Admin
Ooo, those comments are great! I never would have been able to figure out what the LoadPageData() method does otherwise.
I'm almost getting to the point where I think we should remove comments from the language.
Admin
imho It looks more like a copy-and-pasting frenzy gone wrong, rather than an ignorance of not knowing how conditionals work..
Admin
At the place I'm working, I've actually seen code like that second example, and yes, it's in production.
Admin
What is remarkable about the first code example is that there is no "break" for the default case. So there is a little glimpse of hope ...
Admin
See boss. My code isn't so bad at all, look at this: The daily wtf
Admin
Admin
This looks so familiar. A cow-orker (I 'inherited' his code in my last project) used to code like that. But one of his lines is still stuck in my head. I found it while I tried to do a little refactoring on his messy source:
quantity += -1;
I'm glad he's back in testing again.
Admin
Your example makes a bit more sense, because of the default branch.
Admin
I think its clear the first item in this post is a stub for future development. It just looks unfinished. Though I do love the redundant comment.
The second example I could be less forgiving about. One explanation might be changing old, working code to do some new functionality, and not paying attention. You'd be suprised at how many strange bugs can pop up when you throw more developers at a project.
Admin
I once wrote a CASE tool to trap this sort of thing called TERSE: -
"The Eliminator of Redundant Statements Eliminator".
Perhaps I should dig it out and mail it to these people.
Admin
Laugh. Out. Loud. It is pretty hard to squeeze a WTF out of 2 assembly ops worth of code! Thanks for letting me start a Friday with a laugh <3
Admin
"Laugh. Out. Loud. It is pretty hard to squeeze a WTF out of 2 assembly ops worth of code! Thanks for letting me start a Friday with a laugh"
Unless quantity is in a register, in which case only one op is needed:
dec reg;
Admin
Hahahahahahaha, must of never heard of "quantity -= 1;" [:P]
Admin
you must be really stupid to write
quantity += -1;
instead of
quantity -= 1;
I mean, this one is so obvious.
Admin
you must be really stupid to write
quantity -= 1;
instead of
quantity--;
I mean, this one is so obvious.
:-D
Admin
Almost as obvious as quantity--; but who cares? Only the first one is funny.
Admin
I saw a variation on this theme in a production program where the programmer found that a bug fix caused a new bug. The fix was to comment out the new code and reinstate the old code, with a comment to that effect. [:'(]
Better the devil you know...
Admin
And since we're being pedantic, we'd better write
--quantity;
since this doesn't introduce a temporary.
Talking about obvious...
Admin
Any compiler will optimize x++ to be equal to ++x when the expression value is not used and there is no overloaded operator.
It all comes to style. Many prefer x+=1 instead of x++ (or ++x) because they find it more readable. Can't find a reason for X+=-1 though.
Admin
Of course I was thinking of --x, x-- and x-=1 :)
Admin
I think you just invented a new emoticon.
Admin
...
state = null;
...
if(state != null) LoadPageData();
Admin
Depending on the context, the first example may actually be reasonable.
Given that it's branching on "state", it's probably part of a finite state machine -- or an event handler for a GUI, which amounts to the same thing.
If I'm coding a finite state machine by hand, one way or another I need to branch on the combination of state and event, and there are a lot of combinations. In order to keep the code manageable, I typically do the branching in a rigidly stereotyped way. The results may include fragments that, considered in isolation, look just as silly as your example, but that doesn't bother me. It's more important that the repetitive logical structure be immediately recognizable. Also this stereotyped pattern makes it obvious where to put your changes if the state transition diagram changes.
If I'm feeling ambitious, or lazy, I might even write a code generator in Perl or something to take over the tedium of writing voluminous stereotyped code. Again the results may look silly in isolation, but I wouldn't care. I'd rather rely on the compiler to optimize away the redundant tests than trust my own Perl script to treat the corresponding optimization as a special case.