- 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
omg.
Admin
formattedComment.Append("f"); formattedComment.Append("i"); formattedComment.Append("r"); formattedComment.Append("s"); formattedComment.Append("t"); return formattedComment.ToString;
Admin
Ah, the for-case. An easy mistake to make. It just seems so natural.
Admin
Djikstra would be happy. Two or more sequential statements, use a for-case.
Admin
Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
Admin
Admin
[code] For i = 0 To 3 Select Case i Case 0 response.Append("W") Case 1 response.Append("T") Case 2 response.Append("F") Case 3 response.Append("?") End Select Next
Admin
Damn, now you've got me wondering if I've ever done that. I've coded a lot of stupid things in twenty-five years, but I can't remember doing a for-case . . . which means I probably did and then savagely repressed the memory.
Admin
The return of the for-case paradigm!
Admin
Admin
Nice clean and readable piece of code, cheers !
Admin
python-style:
Admin
Bah! Mine goes up to eleven!
Admin
Sorry, let me try again
BAH! Mine goes up to eleven!
Admin
What's wrong with a for-case? It's not needed here (LUT can be used, and would be much better here), but for more advanced decoding it's a perfectly valid way of running a (fixed length) state machine.
I haven't have my coffee yet, but it doesn't look so far fetched.
Admin
I want to see what the StripNonNumericCharacters function looks like!
Admin
Promise me you won't write any code until you've had your coffee.
Admin
Admin
'i' before 'e', except after 'c' ...
Admin
my Str $tired_comment = "";
for 0 .. 2 { when 0 { $tired_comment ~= "W" } when 1 { $tired_comment ~= "T" } when 2 { $tired_comment ~= "F" } }
say $tired_comment;
=end
Really, some people just need to be beaten daily with a good reference for their programming language of choice until they learn that it has more features than the ones they misuse every day.
Admin
Let me help you out
Admin
Yeah, i needed a coffe to see the WTF too. The downside is that I almost choke on it.
Admin
No, a for-case is completely retarded. A while-case is a perfectly valid way of running a state machine. Something like:
int state = 0;
while(state < stateMax) { case 0: // This is probably not a real function call, but a few // lines directly inline, but you get the idea state = doSomethingAndGetNextState(); break; case 1: state = doSomethingAndGetNextState(); break; ... }
If you muck with the state variable in your loop construct, you'll complicate the hell out of your state machine...
Admin
You know, the real WTF and really sad thing is that people who write stuff like that likely get paid way more than I do...
Admin
s/(\d{3})(\d{3})(\d{4})/(\1) \2-\3/
amidoinitrite?
Admin
I too have seen a for-case used for a large state machine. In particular, some of the cases modified the value currently in the for loop, to skip states or to go back states in some cases.
Sadly, instead of making it sane, I added more states to it. Yes, I am ashamed, but sometimes you just gotta get the damn job done and get paid.
Admin
Admin
bashscript'd
for i in
seq 0 3
; do case "$i" in "0") echo -n "W"; ;; "1") echo -n "T"; ;; "2") echo -n "F"; ;; "3") echo; ;; esac; doneAdmin
Admin
OMG, that's a major WTF. No 'Else' case? that's baaaaad. Always put an 'Else' case. Some people never learn. tsk, tsk.
Admin
Admin
Yeah, in my first year as an asp.net coder, I'm pretty sure I did that. Though, I did add length validation so as to not add the parens on a number that was only 7 digits. Looking back, I regret using the for-case.
Admin
At least he put it in a function.
Admin
It's wrong here because you could remove the for and case, and just have the statements execute in order. Using for and case statements to implement a state machine is probably fine (though I'd consider "while" instead of "for"). Using it to implement a linear ordering of statements is not fine; that's what the statement terminator (newline, semicolon, whatever) is for.
Admin
Naw - it's much too readable.
Admin
Admin
Admin
Admin
Typo: Case 9 To 12 ..of course. ;)
Admin
If you look carefully, you'll notice that the code isn't even checking for the right range. A zero-to-twelve loop does 13 passes, not 12.
At least it shouldn't take too long to fix this crap without side-effects. But if this guy managed to screw with something so simple, I can only imagine how awful this system's more complicated functions can be.
And if anyone suppose that the right way to handle a phone validation is a state machine, go back to Programming Logic 101 right away.
Admin
Admin
Admin
Admin
... ...
.... uh.. wow..
That was amazing stupidity.
Almost as bad as an obfuscated 700 line function I saw once in Perl that gets the mean average of an array of numbers. I wish I had code from that project somewhere, that was absolutely amazing, and it took me hours to figure out what it did.
Admin
Admin
My god, I remember when I thought VB was awesome. How stupid and naive I was in those days...
Admin
Admin
Bah, ugly!
print ''.join(['W', 'T', 'F', '!'][i] for i in xrange(4))
Admin
Horrendous.
What is neat is that you can strip away, Picasso-style, and get at the essence of ApplyPhoneNumberFormatting.
Or with lines stripped out:
Certainly braindead, and still worthy of WTF - unless input is guaranteed to be 0 or 9+ numeric characters.
Admin
Ironic that in a post about removing unnecessary lines, you have an if-return-else statement.