| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Next » |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:04
•
by
gosse
(unregistered)
|
|
omg.
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:04
•
by
BK
(unregistered)
|
|
formattedComment.Append("f");
formattedComment.Append("i"); formattedComment.Append("r"); formattedComment.Append("s"); formattedComment.Append("t"); return formattedComment.ToString; |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:09
•
by
daniel
(unregistered)
|
|
Ah, the for-case. An easy mistake to make. It just seems so natural.
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:09
•
by
ross
(unregistered)
|
|
Djikstra would be happy. Two or more sequential statements, use a for-case.
|
|
Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
|
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:12
•
by
slugonamission
(unregistered)
|
|
[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 |
|
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.
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:14
•
by
Médinoc
(unregistered)
|
|
The return of the for-case paradigm!
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:14
•
by
campkev
|
Using the same verification standard, I have verified that my ****** is 10 inches long. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:17
•
by
Rene
(unregistered)
|
|
Nice clean and readable piece of code, cheers !
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:18
•
by
keeper
(unregistered)
|
|
python-style:
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:20
•
by
EPE
(unregistered)
|
|
Bah! Mine goes up to eleven!
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:21
•
by
EPE
(unregistered)
|
|
Sorry, let me try again
BAH! Mine goes up to eleven! |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:21
•
by
JimmyVile
(unregistered)
|
|
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. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:22
•
by
Pim
|
|
I want to see what the StripNonNumericCharacters function looks like!
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:25
•
by
Otterdam
|
Promise me you won't write any code until you've had your coffee. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:29
•
by
some schmoe
(unregistered)
|
Where does it do that? I only see a check for length = 0, otherwise it assumes all the characters are there. So if cleanPhoneNumber comes back with only 9 chars or less, it will blow up. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:31
•
by
Arlen Cuss
(unregistered)
|
|
'i' before 'e', except after 'c' ...
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:31
•
by
MaW
(unregistered)
|
|
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. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:32
•
by
campkev
|
Let me help you out
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:33
•
by
Leonardo
(unregistered)
|
Yeah, i needed a coffe to see the WTF too. The downside is that I almost choke on it. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:33
•
by
WayneCollins
|
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... |
|
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...
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:34
•
by
Kerio
(unregistered)
|
|
s/(\d{3})(\d{3})(\d{4})/(\1) \2-\3/
amidoinitrite? |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:36
•
by
Otto
|
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. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:36
•
by
dpm
|
I beg your pardon! My claim that "the code sucks" was not sarcastic at all. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:36
•
by
daniel
(unregistered)
|
|
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; done |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:36
•
by
Computerquip
(unregistered)
|
>.> Really? If I ever did this, I'd shoot myself.... |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:38
•
by
Nallam
(unregistered)
|
|
OMG, that's a major WTF. No 'Else' case? that's baaaaad. Always put an 'Else' case.
Some people never learn. tsk, tsk. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:40
•
by
Brompot
(unregistered)
|
My ruler is 12 inches. A much more common format. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:41
•
by
Dave
(unregistered)
|
|
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.
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:41
•
by
Addison
(unregistered)
|
|
At least he put it in a function.
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:42
•
by
Technomage
(unregistered)
|
|
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.
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:44
•
by
Trondster
(unregistered)
|
|
Naw - it's much too readable.
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:44
•
by
Vollhorst
(unregistered)
|
Obvious, isn't it? |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:45
•
by
monkeyPushButton
(unregistered)
|
Thanks, now I've gone from laughing to crying... |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:45
•
by
Vollhorst
(unregistered)
|
Previous comment should have quoted this before the code segment. :/ |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:47
•
by
Trondster
(unregistered)
|
|
Typo:
Case 9 To 12 ..of course. ;) |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:48
•
by
Smash King
|
|
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. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:48
•
by
dpm
|
I really, really hope that whatever language that is *guarantees* evaluations are performed in order of appearance, or I'm really, really gonna laugh. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:48
•
by
some schmoe
(unregistered)
|
Ah-ha! |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:49
•
by
dpm
|
You'd let them keep "programmer" as a career choice? You are far more lenient than I. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:50
•
by
Stephen
(unregistered)
|
|
...
... .... 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. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:51
•
by
blindman
(unregistered)
|
Yes, but is it clean? |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:51
•
by
Akoi Meexx
(unregistered)
|
|
My god, I remember when I thought VB was awesome. How stupid and naive I was in those days...
|
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:51
•
by
dpm
|
I see the "0 to 12" and I see "case 0" through "case 12" inclusive, all of which are correct (given the original WTF), so I have no idea what you're complaining about. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:52
•
by
Tempura
(unregistered)
|
|
Bah, ugly!
print ''.join(['W', 'T', 'F', '!'][i] for i in xrange(4)) |
Re: Formatting a Phone Number - The Long Version
2009-03-09 09:53
•
by
Buddy
(unregistered)
|
|
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. |
Re: Formatting a Phone Number - The Long Version
2009-03-09 10:01
•
by
campkev
|
Ironic that in a post about removing unnecessary lines, you have an if-return-else statement. |
| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Next » |