- 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
Haha, terrible, just terrible code. But funny.
Admin
edit. oops. misread the first one.
Admin
Hmm...
If it's a comma, and remains a comma, replace it with a period.
If it's still a comma, and it changes to a quote, replace it with an apostrophe.
Admin
"how many times do you have to check a condition?"
Well we know how many times he thinks he needs to check it.
Admin
The first one must be the in the future when there's quantum computing, where a character can be an comma and a quotation mark at the same time.
Admin
"there are obvious uses that produce cleaner code than strings of else-ifs and help prevent many simple kinds of errors".
And introduce another ones. ;-)
Admin
At least the second snip has a call to the assEvH function. That has a chance of doing something useful.
I wonder if there is an entire ass library.
Admin
ZWINDOW STARCHILD
I especially like the switch that does nothing.
Admin
I have one. Not sure what it has to do with programming though.
captcha doom. I am in a backwards mood today.
Admin
Scare away newbies with a one-liner equivalent
CAPTCHA: muhahaha (how fitting!)
Admin
Mwuahuhauhauhauha
The second one is so ugly, it reminds me of: syntatic sugar causes cancer of the semicolon.
Admin
But if that's the case, the code is WTF! in ways far worse than mere foolish comparisons can express.
Admin
Clearly the first snippet of code is meant to handle race conditions in multi-threaded code. Just because it was a comma a split second ago doesn't mean it hasn't changed so we'd better check again. It's a wonderful way of handling race conditions. Much better than those messy mutexes
Admin
But, shouldn't it decide if it is a comma or a quotation the first time that I look at it?
Admin
That's the amazing thing about C++, sometimes it will tell you the truth, but every once in a while it will lie to you, just for kicks. That's why advanced programming techniques like the one shown come in handy. C++ will never lie twice in a row! It's part of the spec.
Admin
At least the coder of the first example didn't do this: for (i=0; i < strlen(buffer); i++)
:-)
Admin
Better safe than sorry!
Admin
Admin
Hey that's my avatars name on Guild Wars! How dare you post that. Now I'm going to have to change it.
Admin
Admin
Admin
WTF!? How does this account for randomly-changing memory like the original? Plus, you are not utilizing the power of nested ternary operators.
Admin
Eh, well, I guess you've got to make sure that that dastardly operator== method didn't mutilate your string.
Admin
Is that for statement necessary?
Wouldn't that work too? The ++ should get executed after the rest of the expression, so it could equally well be on the second *p, I guess.Admin
who knows, maybe the buffer is volatile. better check twice or thrice to be sure(tm).
Admin
Sorry, can someone explain what's wrong with the second one? As far as I can see there's an unused switch statement that either used to do something or is maybe a placeholder for some thing in the future, but why is it a wtf?
Admin
The first one is obvious; it's highly multi-threaded code, which leads to obscure race conditions.
And the programmer decided to use that phenomenon towards his evil intentions.
Change commas into periods, except if it was changed in between the two checks. Perfectly normal business rule.
Admin
Admin
you leave stuff like that in your production code :O
Admin
Nope sry it's not a placeholder for anything and as far as the older versions tell me there has never been any use of this particular switch.
Admin
"A Real Programmer (TM) can write FORTRAN programs in any language!"
Admin
This brings to mind the first C++ system I ever worked on. It was huge, and the folks who wrote it overloaded every single operator there was in every single class; not because they needed to (named functions would have been far more comprehensible) but because they didn't know when to stop. For example:
....and of course, there was always the inevitable typo sending your data to God-knows-where... (sighs)
Admin
Nah. You can do better than that. For a start:
for(; *p = (*p == ',' ? '.' : *p); p++);
Or, better, including undefined behavior:
while (*p+=(*p++==',')<<1);
Admin
When it comes to good music, Jessica Simpson has some nice boobies...
Admin
You're all wrong. This is obviously code designed to handle old, set in their ways buffers that are resistant to change. ;-)
Admin
You come to a fork in the code; at this branch, there are two sentinels. The specification tells you that one only lies and one only tells the truth, though it is not obvious to you which is which. One code path leads to exit(0) and one leads to exit(-1): asking only one sentinel a single question, how do you determine which branch to take?
Admin
Doesn't work: The post-increment operator makes the *p on the right-hand side different than the *p on the left-hand side.
Admin
You guys, where are you living? You see, it's a internationalization thing we have here. English "," aren't the same than spanish "," So I believe it's checking for these two. Now, the problem is when you want to include any other language, even thought I don't think asian languages use comas... do they?
CAPTCHA: Jeez Mom! For the last time, I won't BATHE I'm a WoW Guru, now leave the garage ASAP
Admin
Admin
It does nothing. After the call to CreateMenu, or wht ever it was, the rest of the code is waste. It loops through a list and preforms some condition check on each object. If the condition is true it executes the switch that does nothing, if false it does nothing.
It loops through a collection and makes no changes. That is superior coding.
Admin
Ohhh, beautiful!
But I never want you to work on anything I get to maintain ;-)
Admin
Holy Frijoles, that 2nd one is mind-boggling.
This line looks like something might have been swallowed by the board, or maybe just a formatting error (parenthesis aren't consistent font): zWindowDlistIter trav(&this->zWindow::kidslist());
Also looks like calling trav's operator() returns the current item and moves the iterator.
I suspect trav() returns a zWindow*, so the dynamic_cast is just for fun?
Admin
The first one reads: copy-paste meets trial-error i.e. a newbie who can't really program takes an existing function and changes it until it does the right thing, which this one accidentally does.
Admin
better: while(*p) *(p++) = *p == ',' ? '.' : *p;
captcha: quake
Admin
Admin
Ah, I see now, he's casting to see if each zWindow* is a zControl*. But then doing nothing with it. Awesome.
Admin
Admin
It works for me:
Outputs:
Hello,"my name is,"what,"my name is Hello."my name is."what."my name is
On VC++ 2003.
It seems that in the second conversion the increment is applied to p after the assignment.
I'm still trying to not think about what's actually happening in the first loop...
Admin
For intentional abuse of the switch statement, I refer you to Duff's Device, one of the most diabolical hacks ever conceived, even more so in that it apparently works and is valid C.
I once attended a lecture given by the aforementioned Tom Duff at SIGGRAPH many years ago. His lecture was somewhat rambling and I don't think completely prepared. He ended the lecture prematurely with the words "Let's abort this pig" and walked off stage.
An amusing and brilliant, if somewhat disorganized, character.
Admin
meh @ second code snippet.
Better worded as: "how to make a non-trivial do_nothing() function".
The captcha summariez everything (again. Do you have some kind of predictive algorithm?): ewww.