Formatting a Phone Number - The Long Version

« Return to Article
  • gosse 2009-03-09 09:04
    omg.
  • BK 2009-03-09 09:04
    formattedComment.Append("f");
    formattedComment.Append("i");
    formattedComment.Append("r");
    formattedComment.Append("s");
    formattedComment.Append("t");
    return formattedComment.ToString;
  • daniel 2009-03-09 09:09
    Ah, the for-case. An easy mistake to make. It just seems so natural.
  • ross 2009-03-09 09:09
    Djikstra would be happy. Two or more sequential statements, use a for-case.
  • dpm 2009-03-09 09:11
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
  • Kermos 2009-03-09 09:11

    for(int i = 0; i < 3; i++)
    {
    switch(i)
    {
    case 0:
    comment.append("W");
    break;
    case 1:
    comment.append("T");
    break;
    case 2:
    comment.append("F");
    break;
    }
    }

    return comment;
  • slugonamission 2009-03-09 09:12
    [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
  • dpm 2009-03-09 09:13
    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.
  • Médinoc 2009-03-09 09:14
    The return of the for-case paradigm!
  • campkev 2009-03-09 09:14
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.

    Using the same verification standard, I have verified that my ****** is 10 inches long.
  • Rene 2009-03-09 09:17
    Nice clean and readable piece of code, cheers !
  • keeper 2009-03-09 09:18
    python-style:

    output = ''
    for i in range(4):
    if i == 0:
    output.append("W")
    elif i == 1:
    output.append("T")
    elif i == 2:
    output.append("F")
    elif i == 3:
    output.append("?")
    print output
  • EPE 2009-03-09 09:20
    Bah! Mine goes up to eleven!
  • EPE 2009-03-09 09:21
    Sorry, let me try again

    campkev:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.

    Using the same verification standard, I have verified that my ****** is 10 inches long.


    BAH! Mine goes up to eleven!
  • JimmyVile 2009-03-09 09:21
    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.

  • Pim 2009-03-09 09:22
    I want to see what the StripNonNumericCharacters function looks like!
  • Otterdam 2009-03-09 09:25
    JimmyVile:
    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.



    Promise me you won't write any code until you've had your coffee.
  • some schmoe 2009-03-09 09:29
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
    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.
  • Arlen Cuss 2009-03-09 09:31
    'i' before 'e', except after 'c' ...
  • MaW 2009-03-09 09:31
    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.
  • campkev 2009-03-09 09:32
    some schmoe:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
    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.


    Let me help you out
    dpm:
    <sarcasm>Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.</sarcasm>
  • Leonardo 2009-03-09 09:33
    Otterdam:
    JimmyVile:
    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.



    Promise me you won't write any code until you've had your coffee.


    Yeah, i needed a coffe to see the WTF too. The downside is that I almost choke on it.
  • WayneCollins 2009-03-09 09:33
    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


    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...
  • Kermos 2009-03-09 09:34
    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...
  • Kerio 2009-03-09 09:34
    s/(\d{3})(\d{3})(\d{4})/(\1) \2-\3/

    amidoinitrite?
  • Otto 2009-03-09 09:36
    Otterdam:
    JimmyVile:
    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.



    Promise me you won't write any code until you've had your coffee.


    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.
  • dpm 2009-03-09 09:36
    campkev:
    some schmoe:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
    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.


    Let me help you out
    dpm:
    <sarcasm>Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.</sarcasm>
    I beg your pardon! My claim that "the code sucks" was not sarcastic at all.
  • daniel 2009-03-09 09:36
    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
  • Computerquip 2009-03-09 09:36
    daniel:
    Ah, the for-case. An easy mistake to make. It just seems so natural.


    >.> Really? If I ever did this, I'd shoot myself....
  • Nallam 2009-03-09 09:38
    OMG, that's a major WTF. No 'Else' case? that's baaaaad. Always put an 'Else' case.
    Some people never learn. tsk, tsk.
  • Brompot 2009-03-09 09:40
    campkev:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.

    Using the same verification standard, I have verified that my ****** is 10 inches long.

    My ruler is 12 inches. A much more common format.
  • Dave 2009-03-09 09:41
    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.
  • Addison 2009-03-09 09:41
    At least he put it in a function.
  • Technomage 2009-03-09 09:42
    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.
  • Trondster 2009-03-09 09:44
    Naw - it's much too readable.

    For i = 0 To 14
    Select Case i
    Case 0
    formattedPhoneNumber.Append("(")
    Case 1,2,3
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(i+1))
    Case 4
    formattedPhoneNumber.Append(") ")
    Case Is < 7
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(i-2))
    Case 8
    formattedPhoneNumber.Append("-")
    Case 9 To 13
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(i-3))
    Case Else
    Return formattedPhoneNumber.ToString
    End Select
    Next
  • Vollhorst 2009-03-09 09:44

    For i = 0 To 12

    Select Case i
    Case 0
    Case 1
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(1))
    Case 2
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(2))
    Case 3
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(3))
    Case 4
    Case 5
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(5))
    Case 6
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(6))
    Case 7
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(7))
    Case 8
    Case 9
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(9))
    Case 10
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(10))
    Case 11
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(11))
    Case 12
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(12))

    End Select

    Next
    Obvious, isn't it?
  • monkeyPushButton 2009-03-09 09:45
    Kermos:
    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...
    Thanks, now I've gone from laughing to crying...
  • Vollhorst 2009-03-09 09:45
    Pim:
    I want to see what the StripNonNumericCharacters function looks like!
    Previous comment should have quoted this before the code segment. :/
  • Trondster 2009-03-09 09:47
    Typo:
    Case 9 To 12
    ..of course. ;)
  • Smash King 2009-03-09 09:48
    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.
  • dpm 2009-03-09 09:48
    Trondster:
    Naw - it's much too readable.

    Case Is < 7
    I really, really hope that whatever language that is *guarantees* evaluations are performed in order of appearance, or I'm really, really gonna laugh.
  • some schmoe 2009-03-09 09:48
    campkev:

    Let me help you out
    dpm:
    <sarcasm>Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.</sarcasm>
    Ah-ha!
  • dpm 2009-03-09 09:49
    Smash King:
    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.
    You'd let them keep "programmer" as a career choice? You are far more lenient than I.
  • Stephen 2009-03-09 09:50
    ...
    ...

    .... 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.

  • blindman 2009-03-09 09:51
    campkev:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.

    Using the same verification standard, I have verified that my ****** is 10 inches long.

    Yes, but is it clean?
  • Akoi Meexx 2009-03-09 09:51
    My god, I remember when I thought VB was awesome. How stupid and naive I was in those days...
  • dpm 2009-03-09 09:51
    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.
    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.
  • Tempura 2009-03-09 09:52
    Bah, ugly!

    print ''.join(['W', 'T', 'F', '!'][i] for i in xrange(4))
  • Buddy 2009-03-09 09:53
    Horrendous.

    What is neat is that you can strip away, Picasso-style, and get at the essence of ApplyPhoneNumberFormatting.


    Public Shared Function ApplyPhoneNumberFormatting(ByVal phoneNumber As String) As String
    Dim cleanPhoneNumber As String
    Dim formattedPhoneNumber As New System.Text.StringBuilder
    'Dim i As Integer

    'If phoneNumber Is Nothing Then
    'Return String.Empty
    'End If

    cleanPhoneNumber = StripNonNumericCharacters(phoneNumber)

    If cleanPhoneNumber.Length = 0 Then
    Return String.Empty
    Else

    'For i = 0 To 12

    'Select Case i
    'Case 0
    formattedPhoneNumber.Append("(")
    'Case 1
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(0))
    'Case 2
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(1))
    'Case 3
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(2))
    'Case 4
    formattedPhoneNumber.Append(") ")
    'Case 5
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(3))
    'Case 6
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(4))
    'Case 7
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(5))
    'Case 8
    formattedPhoneNumber.Append("-")
    'Case 9
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(6))
    'Case 10
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(7))
    'Case 11
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(8))
    'Case 12
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(9))

    'End Select

    'Next

    Return formattedPhoneNumber.ToString

    End If

    End Function


    Or with lines stripped out:


    Public Shared Function ApplyPhoneNumberFormatting(ByVal phoneNumber As String) As String

    Dim cleanPhoneNumber As String
    Dim formattedPhoneNumber As New System.Text.StringBuilder

    cleanPhoneNumber = StripNonNumericCharacters(phoneNumber)

    If cleanPhoneNumber.Length = 0 Then
    Return String.Empty
    Else
    formattedPhoneNumber.Append("(")
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(0))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(1))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(2))
    formattedPhoneNumber.Append(") ")
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(3))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(4))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(5))
    formattedPhoneNumber.Append("-")
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(6))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(7))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(8))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(9))
    Return formattedPhoneNumber.ToString
    End If

    End Function


    Certainly braindead, and still worthy of WTF - unless input is guaranteed to be 0 or 9+ numeric characters.
  • campkev 2009-03-09 10:01
    Buddy:
    Horrendous.

    What is neat is that you can strip away, Picasso-style, and get at the essence of ApplyPhoneNumberFormatting.


    Public Shared Function ApplyPhoneNumberFormatting(ByVal phoneNumber As String) As String
    Dim cleanPhoneNumber As String
    Dim formattedPhoneNumber As New System.Text.StringBuilder
    'Dim i As Integer

    'If phoneNumber Is Nothing Then
    'Return String.Empty
    'End If

    cleanPhoneNumber = StripNonNumericCharacters(phoneNumber)

    If cleanPhoneNumber.Length = 0 Then
    Return String.Empty
    Else

    'For i = 0 To 12

    'Select Case i
    'Case 0
    formattedPhoneNumber.Append("(")
    'Case 1
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(0))
    'Case 2
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(1))
    'Case 3
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(2))
    'Case 4
    formattedPhoneNumber.Append(") ")
    'Case 5
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(3))
    'Case 6
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(4))
    'Case 7
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(5))
    'Case 8
    formattedPhoneNumber.Append("-")
    'Case 9
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(6))
    'Case 10
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(7))
    'Case 11
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(8))
    'Case 12
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(9))

    'End Select

    'Next

    Return formattedPhoneNumber.ToString

    End If

    End Function


    Or with lines stripped out:


    Public Shared Function ApplyPhoneNumberFormatting(ByVal phoneNumber As String) As String

    Dim cleanPhoneNumber As String
    Dim formattedPhoneNumber As New System.Text.StringBuilder

    cleanPhoneNumber = StripNonNumericCharacters(phoneNumber)

    If cleanPhoneNumber.Length = 0 Then
    Return String.Empty
    Else
    formattedPhoneNumber.Append("(")
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(0))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(1))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(2))
    formattedPhoneNumber.Append(") ")
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(3))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(4))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(5))
    formattedPhoneNumber.Append("-")
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(6))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(7))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(8))
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(9))
    Return formattedPhoneNumber.ToString
    End If

    End Function


    Certainly braindead, and still worthy of WTF - unless input is guaranteed to be 0 or 9+ numeric characters.


    Ironic that in a post about removing unnecessary lines, you have an if-return-else statement.
  • Code Dependent 2009-03-09 10:03
    Addison:
    At least he put it in a function.
    Looks more like a func to me.
  • rohypnol 2009-03-09 10:04
    This is actually pretty clean, compared to some of my first coding attempts (which were in kindergarten)...
  • SenTree 2009-03-09 10:10
    Arlen Cuss:
    'i' before 'e', except after 'c' ...
    weird ...
  • bobbytables 2009-03-09 10:11
    How did I know this was going to be VB?
  • ricecake 2009-03-09 10:15
    SenTree:
    Arlen Cuss:
    'i' before 'e', except after 'c' ...
    weird ...
    Or sounding like 'a' as in "neighbor" or "weigh". Not the most leisurely of rhymes. I think I'm going to have a seizure.
  • the real wtf fool 2009-03-09 10:18
    Trondster:
    Naw - it's much too readable.

    I can see some premature optimisations needed:

    dim offset as integer
    offset = 0
    For i = 0 To 12
    Select Case i
    Case 0,4,8
    if i = 8
    formattedPhoneNumber.Append("-")
    else
    formattedPhoneNumber.Append(Chr(40+offset))
    end if
    offset = offset + 1
    Case Else
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(i-offset))
    End Select
    Next
  • Quango 2009-03-09 10:18
    Compile error: formattedComment not defined

    Error: ToString (method) is used like a property

    :-)
  • Sir Twist 2009-03-09 10:18
    JPSoft batch:

    @echo off
    
    do i = 0 to 2
    switch %i
    case 0
    echos W
    case 1
    echos T
    case 2
    echo F
    endswitch
    enddo
  • ContraCorners 2009-03-09 10:18
    Pim:
    I want to see what the StripNonNumericCharacters function looks like!

    My guess would be something like this...

    Public Function StripNonNumericCharacters(ByVal sOrginalPhoneNumber as String) as String

    DIM sCleanPhoneNumber

    sCleanPhoneNumber = Replace(sOrginalPhoneNumber,"A","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"B","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"C","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"D","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"E","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"F","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"G","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"H","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"I","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"J","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"K","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"L","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"M","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"N","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"O","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"P","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"Q","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"R","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"S","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"T","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"U","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"V","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"W","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"X","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"Y","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"Z","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"a","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"b","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"c","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"d","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"e","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"f","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"g","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"h","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"i","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"j","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"k","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"l","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"m","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"n","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"o","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"p","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"q","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"r","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"s","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"t","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"u","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"v","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"w","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"x","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"y","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"z","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"`","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"~","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"!","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"@","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"#","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"$","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"%","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"^","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"&","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"*","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"(","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,")","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"_","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"-","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"+","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"=[","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"]","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"\","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"{","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"}","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"|","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,";","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,";","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"""","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"'","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,",.","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"/","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"<","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,">","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"?","")

    return sCleanPhoneNumber

    End Function
  • Pim 2009-03-09 10:23
    ricecake:
    Or sounding like 'a' as in "neighbor" or "weigh". Not the most leisurely of rhymes. I think I'm going to have a seizure.
    Yes, the English language has strange grammar policies!
  • pscs 2009-03-09 10:29
    ricecake:
    SenTree:
    Arlen Cuss:
    'i' before 'e', except after 'c' ...
    weird ...
    Or sounding like 'a' as in "neighbor" or "weigh". Not the most leisurely of rhymes. I think I'm going to have a seizure.


    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).

  • juju 2009-03-09 10:35
    some schmoe:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
    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.


    Indeed it will blow up. Maybe the function that returns the 'clean' phone number returns an empty string if the number is not in the correct format to begin with. We can only hope!
  • Right tool for the right job 2009-03-09 10:37
    I use for loops for everything!
    I use for loops for everything!
    I use for loops for everything!
    I use for loops for everything!
  • TwelveBaud 2009-03-09 10:37
    But my phone numbers are
    +44 (20) 7555-1234
    and
    +881 (7) 5555-1234
    !

    How will I be able to enter them now?
  • Anonymous 2009-03-09 10:38
    Vollhorst:

    For i = 0 To 12

    Select Case i
    Case 0
    Case 1
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(1))
    Case 2
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(2))
    Case 3
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(3))
    Case 4
    Case 5
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(5))
    Case 6
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(6))
    Case 7
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(7))
    Case 8
    Case 9
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(9))
    Case 10
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(10))
    Case 11
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(11))
    Case 12
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(12))

    End Select

    Next
    Obvious, isn't it?


    Clear as water...
  • campkev 2009-03-09 10:39
    pscs:
    ricecake:
    SenTree:
    Arlen Cuss:
    'i' before 'e', except after 'c' ...
    weird ...
    Or sounding like 'a' as in "neighbor" or "weigh". Not the most leisurely of rhymes. I think I'm going to have a seizure.


    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).



    While I agree with you that the rule is almost useless, some of your examples are kind of WTF themselves. The rule is only meant for situations where the i and the e make a single sound. In science, society, deity and seeing, the i and the e are part of different syllables. Also, eider is Swedish, so you can hardly expect an English grammar rule to apply.
  • nerf 2009-03-09 10:42
    At least it uses stringbuilder, and doesn't use &=. Too bad he didn't go two down in intellisense...

    formattedPhoneNumber.AppendFormat("({0}) {1}-{2}", cleanPhoneNumber.Substring(0, 3), cleanPhoneNumber.Substring(4, 3), cleanPhoneNumber.Substring(7, 4))

  • Gieron 2009-03-09 10:42
    Reminds me of Duff's device.
  • Kermos 2009-03-09 10:43
    pscs:

    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).



    Oh yea, English is such a clusterfuck of exceptions that it really is 'exceptional'. I have friends in Taiwan and Japan that I occasionally help with their English studies. Really makes you realize what a mess it all is when you try to explain it to someone and go "WTF..." in your mind. :)

  • Someone who likes shorter versions 2009-03-09 10:43
    Public Shared Function ApplyPhoneNumberFormatting(ByVal phoneNumber As String) As String
    Dim cleanPhoneNumber As String

    If phoneNumber Is Nothing Then
    Return String.Empty
    End If

    cleanPhoneNumber = StripNonNumericCharacters(phoneNumber)

    If cleanPhoneNumber.Length = 0 Then
    Return String.Empty
    Else
    Return "(" + Mid(cleanPhoneNumber, 0, 3) + ")" + Mid(cleanPhoneNumber, 3, 3) + "-" + Mid(cleanPhoneNumber), 6, 4);
    End If
    End Function
  • Anonymous 2009-03-09 10:45
    Please supply me with a firearm and the coder responsible for this abomination. Then just close the door behind you and pretend you didn't see me today.
  • Ditto 2009-03-09 10:49
    Shouldn't that address be:

    For Loop Liberation Front
    44 Front St. 2nd Floor
    Berea, OH 44017
    USA
    End Loop

    ?? :\

    (Uh, and the CAPTCHA was: transverbero .. what the heck is that? a verb with questionable gender?) :o
  • len(10)=12 2009-03-09 10:50
    campkev:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.

    Using the same verification standard, I have verified that my ****** is 10 inches long.


    It may only be 10 inches, but sure smells like 1'
  • Code Dependent 2009-03-09 10:51
    ContraCorners:
    Pim:
    I want to see what the StripNonNumericCharacters function looks like!

    My guess would be something like this...
    *snip*
    Even if you used a macro to generate that, you have waay too much time on your hands.
  • zzo38 2009-03-09 10:57
    This FOR-CASE construct has been seen before on Daily WTF before I think. Really the only reason I can think of is to simulate line-numbers and most programs don't need them (even if they have them).
  • diaphanein 2009-03-09 11:09
    Bah, this is nothing. I perhaps some of the most horrendous legacy code I inheritted, I have a single function that I've so far reduced to 977 lines (was previously +1500).

    At last count, there's over a dozen of non-const static locals (hooray for non-reentrant code).

    There are:
    7 while loops.
    25 for loops.
    27 nested switch statements.
    81 cases for those switch statements.
    261 if statements.
    123 else statements.

    As I said, this phone number loops is NOTHING. It's not a WTF, it's a meh.
  • More 2009-03-09 11:15
    ContraCorners:
    Pim:
    I want to see what the StripNonNumericCharacters function looks like!

    My guess would be something like this...
    <snip>


    Don't be silly. This is much more eloquent:

    Public Function StripNonNumericCharacters(ByVal sOrginalPhoneNumber As String) As String
    Dim i As Integer

    Dim sCleanPhoneNumber
    If sOrginalPhoneNumber Is Nothing Then
    Return String.Empty
    Else
    For i = 0 To 83
    Select Case i
    Case 0
    sCleanPhoneNumber = Replace(sOrginalPhoneNumber, "A", "")
    Case 1
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "B", "")
    Case 2
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "C", "")
    Case 3
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "D", "")
    Case 4
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "E", "")
    Case 5
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "F", "")
    Case 6
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "G", "")
    Case 7
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "H", "")
    Case 8
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "I", "")
    Case 9
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "J", "")
    Case 10
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "K", "")
    Case 11
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "L", "")
    Case 12
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "M", "")
    Case 13
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "N", "")
    Case 14
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "O", "")
    Case 15
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "P", "")
    Case 16
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "Q", "")
    Case 17
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "R", "")
    Case 18
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "S", "")
    Case 19
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "T", "")
    Case 20
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "U", "")
    Case 21
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "V", "")
    Case 22
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "W", "")
    Case 23
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "X", "")
    Case 24
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "Y", "")
    Case 25
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "Z", "")
    Case 26
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "a", "")
    Case 27
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "b", "")
    Case 28
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "c", "")
    Case 29
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "d", "")
    Case 30
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "e", "")
    Case 31
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "f", "")
    Case 32
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "g", "")
    Case 33
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "h", "")
    Case 34
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "i", "")
    Case 35
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "j", "")
    Case 36
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "k", "")
    Case 37
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "l", "")
    Case 38
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "m", "")
    Case 39
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "n", "")
    Case 40
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "o", "")
    Case 41
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "p", "")
    Case 42
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "q", "")
    Case 43
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "r", "")
    Case 44
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "s", "")
    Case 45
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "t", "")
    Case 46
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "u", "")
    Case 47
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "v", "")
    Case 48
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "w", "")
    Case 49
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "x", "")
    Case 50
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "y", "")
    Case 51
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "z", "")
    Case 52
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "`", "")
    Case 53
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "~", "")
    Case 54
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "!", "")
    Case 55
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "@", "")
    Case 56
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "#", "")
    Case 57
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "$", "")
    Case 58
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "%", "")
    Case 59
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "^", "")
    Case 60
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "&", "")
    Case 61
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "*", "")
    Case 62
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "(", "")
    Case 63
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, ")", "")
    Case 64
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "_", "")
    Case 65
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "-", "")
    Case 66
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "+", "")
    Case 67
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "=[", "")
    Case 68
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "]", "")
    Case 69
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "\", "")
    Case 70
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "{", "")
    Case 71
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "}", "")
    Case 72
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "|", "")
    Case 73
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, ";", "")
    Case 74
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "", "")
    Case 75
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, ";", "")
    Case 76
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, """", "")
    Case 77
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "'", "")
    Case 78
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "", "")
    Case 79
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, ",.", "")
    Case 80
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "/", "")
    Case 81
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "<", "")
    Case 82
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, ">", "")
    Case 83
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "?", "")

    End Select
    Next
    Return sCleanPhoneNumber
    End If
    End Function
  • Henk 2009-03-09 11:38
    def bla(a):
    return '('+a[:3]+') '+a[3:6]+'-'+a[6:]
  • foo 2009-03-09 11:40
    diaphanein:
    Bah, this is nothing. I perhaps some of the most horrendous legacy code I inheritted, I have a single function that I've so far reduced to 977 lines (was previously +1500).

    At last count, there's over a dozen of non-const static locals (hooray for non-reentrant code).

    There are:
    7 while loops.
    25 for loops.
    27 nested switch statements.
    81 cases for those switch statements.
    261 if statements.
    123 else statements.

    As I said, this phone number loops is NOTHING. It's not a WTF, it's a meh.


    Awesome. I am applying for the domain name "thedailymeh.com". In the future please direct all of your submissions to me.
  • campkev 2009-03-09 11:45
    Kermos:
    pscs:

    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).



    Oh yea, English is such a clusterfuck of exceptions that it really is 'exceptional'. I have friends in Taiwan and Japan that I occasionally help with their English studies. Really makes you realize what a mess it all is when you try to explain it to someone and go "WTF..." in your mind. :)



    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.
  • Buddy 2009-03-09 11:46
    campkev:
    Buddy:
    Horrendous.

    What is neat is that you can strip away, Picasso-style, and get at the essence of ApplyPhoneNumberFormatting.

    ...


    Ironic that in a post about removing unnecessary lines, you have an if-return-else statement.


    It's a work in progress, each step I have to tread every more carefully to ensure I capture the true essence of what is ApplyPhoneNumberFormatting.


  • Dennis 2009-03-09 11:48
    dpm:
    campkev:
    some schmoe:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
    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.


    Let me help you out
    dpm:
    Yeah, the code sucks, <sarcasm>but at least the length is verified before they try to access all ten digits they expect to be there.</sarcasm>
    I beg your pardon! My claim that "the code sucks" was not sarcastic at all.


    fix'd
  • ContraCorners 2009-03-09 11:49
    More:
    ContraCorners:
    Pim:
    I want to see what the StripNonNumericCharacters function looks like!

    My guess would be something like this...
    <snip>


    Don't be silly. This is much more eloquent:

    Public Function StripNonNumericCharacters(ByVal sOrginalPhoneNumber As String) As String
    Dim i As Integer

    Dim sCleanPhoneNumber
    If sOrginalPhoneNumber Is Nothing Then
    Return String.Empty
    Else
    For i = 0 To 83
    Select Case i
    Case 0
    sCleanPhoneNumber = Replace(sOrginalPhoneNumber, "A", "")
    Case 1
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "B", "")
    < snip >
    Case 83
    sCleanPhoneNumber = Replace(sCleanPhoneNumber, "?", "")

    End Select
    Next
    Return sCleanPhoneNumber
    End If
    End Function
    cc



    D'oh! What was I thinking?! Thanks for your help, I stand corrected.
  • SCB 2009-03-09 11:53
    Brompot:
    campkev:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.

    Using the same verification standard, I have verified that my ****** is 10 inches long.

    My ruler is 12 inches. A much more common format.


    Maybe, but his is metric.
  • tombom 2009-03-09 11:57
    Petition to name this XTREME CODING STYLE "Duff's Enigma"
  • Code Dependent 2009-03-09 11:57
    campkev:
    As an example, he asked if anyone could give the past tense of "I can go"?
    I used to be able to go (but now I wear a catheter).
  • Buddy 2009-03-09 11:58
    campkev:

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.


    If I'm understanding correctly...

    Today, I can go, but yesterday, I could have gone.
  • Inno 2009-03-09 11:58
    campkev:


    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.


    English is not my native language, but how about:
    1) I could go
    2) I could have gone
  • Anon 2009-03-09 11:58
    campkev:
    Kermos:
    pscs:

    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).



    I could of gone?

    Oh yea, English is such a clusterfuck of exceptions that it really is 'exceptional'. I have friends in Taiwan and Japan that I occasionally help with their English studies. Really makes you realize what a mess it all is when you try to explain it to someone and go "WTF..." in your mind. :)



    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.
  • Anon 2009-03-09 11:59
    [quote user="campkev"][quote user="Kermos"]

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.[/quote]

    Sorry, messed that up:

    I could of gone?
  • Kermos 2009-03-09 12:02
    [quote user="Anon"][quote user="campkev"][quote user="Kermos"]

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.[/quote]

    Sorry, messed that up:

    I could of gone?[/quote]

    Yep, you definitely messed that up...
  • Devilfish 2009-03-09 12:03
    If this doesn't make you cry, you have no soul.
  • BrianA 2009-03-09 12:06
    Even VB6 can do it better:

    Public Function ApplyPhoneNumberFormatting(ByVal phoneNumber As String) As String

    Dim cleanPhoneNumber As String

    cleanPhoneNumber = StripNonNumericCharacters(phoneNumber)

    If cleanPhoneNumber.Length = 0 Then
    ApplyPhoneNumberFormatting = ""
    Else
    ApplyPhoneNumberFormatting = Format(cleanPhoneNumber, "(@@@) @@@-@@@@")
    End If

    End Function
  • campkev 2009-03-09 12:06
    Code Dependent:
    campkev:
    As an example, he asked if anyone could give the past tense of "I can go"?
    I used to be able to go (but now I wear a catheter).


    I could go

    I could have gone

    I could of gone?


    Four responses, all different. Is the right answer even necessary to make my point?


  • Sofa King 2009-03-09 12:10
    As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.

    You're telling us not one of 300 people could come up with "I could have gone?" That seems implausible.
  • YourNameHere 2009-03-09 12:12
    bobbytables:
    How did I know this was going to be VB?

    Darn you beat me to my comment.
  • The Wanderer 2009-03-09 12:21
    Sofa King:
    As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.

    You're telling us not one of 300 people could come up with "I could have gone?" That seems implausible.

    That was my first thought as well, but isn't that a conditional (thus, past tense of "I could go") rather than a strict past tense?

    Which would (now that I think of it) seem to lead to "I can have gone" as the correct answer, but since I went through three other possibilities leading to it, the original point of English being complicated in this respect does seem to have some validity.
  • campkev 2009-03-09 12:23
    Sofa King:
    As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.

    You're telling us not one of 300 people could come up with "I could have gone?" That seems implausible.


    No, someone came up with "I could have gone", it just isn't right.
  • Code Dependent 2009-03-09 12:23
    Anon:
    I could of gone?
    I could of gone, except I of to of something to eat first.
  • campkev 2009-03-09 12:25
    Code Dependent:
    Anon:
    I could of gone?
    I could of gone, except I of to of something to eat first.


    Don't be mean, he did say he wasn't a native speaker, and if you've only heard it said, "could've gone" sounds a lot like "could of".
  • Fred Foobar 2009-03-09 12:26

    (let ((comment '()))
    (dotimes (x 4)
    (cond
    ((= x 0) (push #\W comment)
    (= x 1) (push #\T comment)
    (= x 2) (push #\F comment)
    (= x 3) (push #\? comment))))
    (coerce (nreverse comment) 'string))
  • Anon 2009-03-09 12:28
    [quote user="Kermos"][quote user="Anon"][quote user="campkev"][quote user="Kermos"]

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.[/quote]

    Sorry, messed that up:

    I could of gone?[/quote]

    Yep, you definitely messed that up...
    [/quote]

    Whoops total brain fart. I meant I could've gone or could have.
  • snoofle 2009-03-09 12:34
    campkev:
    ...he asked if anyone could give the past tense of "I can go"?


    I could go (past tense, contrasted with the present tense: I could go)
    I could have gone
    I might have gone
    I may have gone
    File not found

    What's so hard?
  • Code Dependent 2009-03-09 12:38
    snoofle:
    campkev:
    ...he asked if anyone could give the past tense of "I can go"?


    I could go (past tense, contrasted with the present tense: I could go)
    I could have gone
    I might have gone
    I may have gone
    File not found

    What's so hard?
    I'm sticking with "I used to be able to go." Or, if you want redneck vernacular, "I usta cud go."
  • derula 2009-03-09 12:44
    comment = ""
    
    for i in 0..9
    case i
    when 0 then comment << "R"
    when 1 then comment << "u"
    when 2 then comment << "b"
    when 3 then comment << "y"
    when 4 then comment << " "
    when 5 then comment << ">"
    when 6 then comment << " "
    when 7 then comment << "%"
    when 8 then comment << "s"
    when 9 then comment << "!"
    end
    end
    printf comment, "VB"
  • Someone You Know 2009-03-09 12:44
    campkev:

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.


    I am surprised no one has yet suggested "I was able to go".
  • campkev 2009-03-09 12:45
    Someone You Know:
    campkev:

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.


    I am surprised no one has yet suggested "I was able to go".


    Ladies and gentleman, we have a winner!
  • ContraCorners 2009-03-09 12:46
    campkev:
    Sofa King:
    As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.

    You're telling us not one of 300 people could come up with "I could have gone?" That seems implausible.


    No, someone came up with "I could have gone", it just isn't right.


    I have gone.
  • SCB 2009-03-09 12:53
    campkev:
    Someone You Know:
    campkev:

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.


    I am surprised no one has yet suggested "I was able to go".


    Ladies and gentleman, we have a winner!


    But the present tense of "I was able to go" is "I am able to go", not "I can go".
    Explain that please.
  • Kermos 2009-03-09 12:56
    The Wanderer:
    Sofa King:
    As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.

    You're telling us not one of 300 people could come up with "I could have gone?" That seems implausible.

    That was my first thought as well, but isn't that a conditional (thus, past tense of "I could go") rather than a strict past tense?

    Which would (now that I think of it) seem to lead to "I can have gone" as the correct answer, but since I went through three other possibilities leading to it, the original point of English being complicated in this respect does seem to have some validity.


    Easy in Japanese though. :)

    行く - iku- go
    行った - itta - went
    行ける - ikeru - can go / be able to go
    行けた - iketa - have gone / was able to go

    I swear, the next person that looks at me all wide eyed when they find out I study Japanese and asks me, in English nonetheless, "Isn't that too difficult?" is gonna be beaten senseless with a rubber chicken.
  • Neeneko 2009-03-09 12:56
    WayneCollins:

    No, a for-case is completely retarded. A while-case is a perfectly valid way of running a state machine.


    I disagree.

    For starters, why have the complexity of a variable state machine when a linear one is all you need? If all you need is 'nextState = currState+1' then there is no need for a nextState function, in fact a nextState function would be more error prone.

    There is also the other use for for-case constructs, which is when you have some function you need to execute between each state (debugging begin a common example).

    If you muck with the state variable in your loop construct, you'll complicate the hell out of your state machine...


    If you have to add real complexity in order to avoid perceived complexity, you are doing it wrong ;p

    A while-case loop is perfectly valid but not always superior to for-case when putting together state machines.
  • Jeremy 2009-03-09 12:57
    SCB:
    But the present tense of "I was able to go" is "I am able to go", not "I can go".
    Explain that please.

    There isn't a difference between "I can verb" and "I am able to verb."
  • pscs 2009-03-09 13:01
    [quote user="ContraCorners"]
    No, someone came up with "I could have gone", it just isn't right.[/quote]
    I have gone.[/quote]

    That's not right either.

    I could have gone might be past tense or might be conditional. So it might have been right.
    I might have gone is also possibly conditional.

    "I was able to go" is right, also "I had been able to go". You have to convert the modal verb 'can' to the 'to be able to' form. You have difficulty converting modal verbs (verbs which change the 'mode' of another verb) to past tense.

    With 'I can go', the verb is 'to go', the 'can' changes the 'mode' of that verb. 'can' is not the verb.

    Many languages don't have modal verbs, it's generally Germanic ones which do. Romantic languages change the verb form itself.

    We had this at my kids' school - they had to give the future tense of various verbs (at age 7), 'can' being one of them. I did suggest various options to my son, either to be a smart-alec and suggest that modal verbs might not be the best examples for this exercise, or to be awkward and take 'to can' as the verb, and write 'They will can the beans in the factory tomorrow' as the answer, but eventually we just said 'They will be able to go cycling at the weekend'.
  • WayneCollins 2009-03-09 13:03
    Neeneko:
    WayneCollins:

    No, a for-case is completely retarded. A while-case is a perfectly valid way of running a state machine.


    I disagree.

    For starters, why have the complexity of a variable state machine when a linear one is all you need? If all you need is 'nextState = currState+1' then there is no need for a nextState function, in fact a nextState function would be more error prone.

    There is also the other use for for-case constructs, which is when you have some function you need to execute between each state (debugging begin a common example).

    If you muck with the state variable in your loop construct, you'll complicate the hell out of your state machine...


    If you have to add real complexity in order to avoid perceived complexity, you are doing it wrong ;p

    A while-case loop is perfectly valid but not always superior to for-case when putting together state machines.


    I see what you mean. If your state machine has next state almost always equal to current state + 1, then for-case is less verbose and error prone. On the other hand, if at a given state you must unconditionally go to state + 1, why have separate states for those two parts?
  • Buddy 2009-03-09 13:05
    SCB:

    But the present tense of "I was able to go" is "I am able to go", not "I can go".
    Explain that please.


    The verb "can" has no infinitive. The closest is "to be able to". Dependent formations will not be 100% reversible.

    Technically, English doesn't have infinitives, most tenses, or even a grammar in the sense of inflected languages like Latin and old Greek (from which grammar terms were derived).

    It has "-s/-es" for plural, "-'s/-'" for possessive, "-ed" for past tense, and "-ly" for adverbs. Everything else is a cobbled word-order-based mishmash of exceptions.
  • Neil 2009-03-09 13:07
    campkev:

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.


    The example might prove that there is some complexity in English, but it certainly doesn't prove anything about English in relationship to any other language. The reality of language learning difficulty has a lot to do with the age you pick up the language and the relationship of the language to the native language. I'll bet a native German speaker wouldn't find English as difficult and complex to learn as they would Chinese.
  • m0ffx 2009-03-09 13:11
    Yeah, the verb 'can' is a bit weird. And English spelling is very oddball.

    But there's an awful lot that's SIMPLE about English.

    * Few tenses (compared to some languages).
    * Only one (modern) form of 'you'.
    * The only noun-verb agreement is singular vs plural. There's no need for noun-adjective agreement.
    * No 'gender' for inanimate objects.
  • pscs 2009-03-09 13:11
    campkev:
    pscs:

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).



    While I agree with you that the rule is almost useless, some of your examples are kind of WTF themselves. The rule is only meant for situations where the i and the e make a single sound.

    Agreed, but it doesn't say that. It isn't "I before E except after C as long as it's only a single sound....."

    Also, that still goes wrong with Keith, Seismic, ancient etc.

    Also, eider is Swedish, so you can hardly expect an English grammar rule to apply.

    But... most English words aren't English, they're mostly originally derived from German, French, Scandinavian, Latin, Greek etc.

    Eider may have originally been a Swedish word, but if you go to a department store and ask for an Eiderdown (at least in the UK), they'll sell you a quilt (probably without any duck feathers in), they won't go hunting for a Swedish-English dictionary. We have co-opted the word as an English word.

    IIRC the 'I before E' rule does apply more to words with certain languages as the root language, but that doesn't really help most people. Many of the 'strangenesses' of English make more sense if you know which language the words came from originally and have different rules depending on the words' origins.

    English is just so bizarre because it is a mixture of so many different languages shoved together. This actually seems to make it easier than other languages for people from other countries to learn enough to make themselves understood - despite what logic would suggest. You could say that English is sort of a 'natural' Esperanto ;)

  • Kermos 2009-03-09 13:13
    Neil:
    campkev:

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.


    The example might prove that there is some complexity in English, but it certainly doesn't prove anything about English in relationship to any other language. The reality of language learning difficulty has a lot to do with the age you pick up the language and the relationship of the language to the native language. I'll bet a native German speaker wouldn't find English as difficult and complex to learn as they would Chinese.


    I actually happen to be a native German speaker and while I picked up English obviously without a problem, I don't find Japanese particularly difficult or complex. Learning to read is time consuming (writing has an alphabet one can fall back to, unlike Chinese) but grammar is not bad because it is extremely consistent.

    I honestly though did never realize how complex English can be (and even worse yet German) until studying Japanese and trying to explain English to friends who have never set foot into an English speaking country.
  • Neeneko 2009-03-09 13:13
    WayneCollins:
    On the other hand, if at a given state you must unconditionally go to state + 1, why have separate states for those two parts?


    The only times I've seen such a construct being used sanely were either:

    (a) states were pulled from a function table which, while always linear, changed according to some earlier condition such as gender, region, user type, website of origin, etc. nice clean way of having data-driven linear state machines.

    (b) cases where each state (possibly from a table or generic) had some kind of prologue/epilogue function. So things like:


    for(1..n):
    {
    doStuff()
    switch(i)
    1: Something()
    break;
    2: Something else()
    break;
    n: Blah blah()
    break;
    doOtherStuff()
    }


    and I guess (c) times where you want to use the switch-case fallthrough, which is probably more mess then it is worth but sometimes really helpful. i.e.:


    for(1..n):
    {
    doStuff()
    switch(i)
    1: Something()
    //fall through, so (1) runs (1) and (2)
    2: Something else()
    break;
    n: Blah blah()
    break;
    doOtherStuff()
    }
  • hallo.amt 2009-03-09 13:14
    To be honest, I do not see any problems with that. Any good compiler could probably optimize that out...
    Or maybe not.

    But in Germany phone numbers can be from something like
    (0 89) 1 23
    getting a little more complex with
    (0 76 71) 2 03
    (0 76 24) 98 55 46 1
    to somethiing like
    (0 24 95) 1 25 46 39 - 2 45 41

    I do not see how this code could handle these numbers. It is not really complex but the grouping is starting on the right hand side.

    So let's praise this great developer
  • gallier2 2009-03-09 13:17
    Reminds me of my former collegue. He was able to do atol (ascii to long integer for the C challenged) in 150 lines of C code.
    He used the same 'paradigm' as todays WTF, but extended it by using 10 different for loops with integrated switch/case using a big switch/case

    something like that:

    char *buf;
    int len = strlen(buf);
    long res = 0;

    switch(len)
    {
    case 1:
    for(i=0; i<1; i++) {
    switch(i) {
    case 0: res = buf[0]-'0';
    }
    }
    break;

    case 2:
    for(i=0; i<2; i++)
    {
    switch(i)
    {
    case 0:
    res = buf[0]-'0';
    break;
    case 1:
    res = res * 10 + buf[1]-'0';
    break;
    }
    }
    break;

    case 3:
    for(i=0; i<3; i++)
    {
    switch(i)
    {
    case 0:
    res = buf[0]-'0';
    break;
    case 1:
    res = res * 10 + buf[1]-'0';
    break;
    case 2:
    res = res * 100 + buf[2]-'0';
    break;
    }
    }
    break;
    ...


    you get the point.

    (again for the C challenged one could write it this way:

    char *buf;
    int len = strlen(buf);
    long res = 0;

    for(i=0; i<len; i++)
    res = res*10 + (buf[i]-'0');


    or even better, using the standard library:


    long res = atol(buf);

  • The Wanderer 2009-03-09 13:24
    Kermos:
    The Wanderer:
    Sofa King:
    You're telling us not one of 300 people could come up with "I could have gone?" That seems implausible.

    That was my first thought as well, but isn't that a conditional (thus, past tense of "I could go") rather than a strict past tense?

    Which would (now that I think of it) seem to lead to "I can have gone" as the correct answer, but since I went through three other possibilities leading to it, the original point of English being complicated in this respect does seem to have some validity.


    Easy in Japanese though. :)

    Well, of course. Japanese is far more regular than English in that respect. It's figuring out the cases where it *is* irregular, and the ways in which it can be warped in common usage (leaving out words and so forth), which get complicated.

    Well, that and the kanji. But that's mostly a matter of practice.
    Kermos:
    行く - iku- go
    行った - itta - went
    行ける - ikeru - can go / be able to go
    行けた - iketa - have gone / was able to go

    I swear, the next person that looks at me all wide eyed when they find out I study Japanese and asks me, in English nonetheless, "Isn't that too difficult?" is gonna be beaten senseless with a rubber chicken.

    Japanese isn't terribly complicated, but except for the basics, it isn't what I'd call easy. English is significantly worse, yes, but people who ask that kind of question in English probably didn't learn it as a second language.
  • Coward 2009-03-09 13:25
    campkev:
    Someone You Know:
    campkev:

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.


    I am surprised no one has yet suggested "I was able to go".


    Ladies and gentleman, we have a winner!

    What about "I went"?

    CAPTCHA: pecus
  • RobFreundlich 2009-03-09 13:27
    ricecake:
    SenTree:
    Arlen Cuss:
    'i' before 'e', except after 'c' ...
    weird ...
    Or sounding like 'a' as in "neighbor" or "weigh". Not the most leisurely of rhymes. I think I'm going to have a seizure.


    A nice sentence to remember some common exceptions, courtesy of my wife's grandmother:

    The weird foreigner netiher seizes leisure nor forfeits height.
  • Ben 2009-03-09 13:27
    Joining the OT language discussion I refer you to the great essay "The awful german language" by Mark Twain (available online, easy found via Google).
    Now who's worse? ;-)
  • On-Anon 2009-03-09 13:29
    campkev:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.

    Using the same verification standard, I have verified that my ****** is 10 inches long.


    Your banger?

    Captcha: jugis
  • Someone You Know 2009-03-09 13:30
    campkev:
    Someone You Know:
    campkev:

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.


    I am surprised no one has yet suggested "I was able to go".


    Ladies and gentleman, we have a winner!


    Thank you.

    For the record, and since no one seems to have objected to this one yet, "I used to be able to go" is the imperfect tense, not the past tense.

    This is complicated by the fact that the words "I was able to go" could also be used for the imperfect tense.
  • DaveK 2009-03-09 13:39
    campkev:
    Code Dependent:
    Anon:
    I could of gone?
    I could of gone, except I of to of something to eat first.


    Don't be mean, he did say he wasn't a native speaker, and if you've only heard it said, "could've gone" sounds a lot like "could of".
    So he's not a native speaker of English, he's a Brummie?
  • A Nonny Mouse 2009-03-09 13:39
    Someone You Know:
    campkev:
    Someone You Know:
    campkev:

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.


    I am surprised no one has yet suggested "I was able to go".


    Ladies and gentleman, we have a winner!


    Thank you.

    For the record, and since no one seems to have objected to this one yet, "I used to be able to go" is the imperfect tense, not the past tense.

    This is complicated by the fact that the words "I was able to go" could also be used for the imperfect tense.


    "i could have gone" and "i was able to go" mean exactly the same thing
  • Benanov 2009-03-09 13:45
    campkev:

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.


    The "can" throws a wrench in it. I believe the only tense that works with "can" is past perfect: "I could have gone."

    (I think subjunctive is the correct tense in Spanish. It's been ten years since I took Spanish.)

    "I can go any time I like"
    "I could have gone any time I liked"

    I can go to the store
    I could've gone to the store

    Edit: ninja'd

    English is interesting--unlike negatives (where each negative term is like multiplying the statement by -1) I think you have to convert all verbs to agree and use past tense.
  • John 2009-03-09 13:49
    I used to work for a company where this method of writing was standard - even approved of. No-one could explain why they did it - they just did it.
  • Kermos 2009-03-09 13:57
    John:
    I used to work for a company where this method of writing was standard - even approved of. No-one could explain why they did it - they just did it.


    I am really glad your comment starts with "I used to..."
  • campkev 2009-03-09 14:04
    A Nonny Mouse:

    "i could have gone" and "i was able to go" mean exactly the same thing


    Really? Would you ever say "I could have gone" about something you actually went to?
  • Code Dependent 2009-03-09 14:15
    Neil:
    The reality of language learning difficulty has a lot to do with the age you pick up the language
    Definitely true. I have a friend who took French in college, but has not used it since. She remembers the basic rules, but has forgotten most of the words and phrases. She recently started working as a nanny for a couple who have six month old and three year old daughters. The father is native German, the mother native French; they moved to the United States about four years ago. The father only speaks to his children in German, and the mother only in French.

    The three year old not only speaks fluent German, French and English, but intermingles them. She isn't really aware of them as separate languages. For example, my friend told me the girl said to her, "Miss Linda, come with me into the salon." In the US it's called a living room, not a salon.

    The girl wanted Linda to read her a book, but all her books are in German or French. So Linda picked a French one and did the best she could by calling on her college French classes. But the little girl started laughing at her and said she sounded silly. Linda said, "But can you tell what I am saying?" and she answered, "No!"
  • EndlessWaves 2009-03-09 14:19
    campkev:
    A Nonny Mouse:

    "i could have gone" and "i was able to go" mean exactly the same thing


    Really? Would you ever say "I could have gone" about something you actually went to?


    I came to a junction in the maze, I could have gone either way but the force was strong at that time and guided me down the right path.
  • Code Dependent 2009-03-09 14:20
    Someone You Know:
    For the record, and since no one seems to have objected to this one yet, "I used to be able to go" is the imperfect tense, not the past tense.

    This is complicated by the fact that the words "I was able to go" could also be used for the imperfect tense.
    Now you're really getting nitpicky.

    Once upon a time, I could go.
    In the past, I could have chosen to go.
    I once had the power of choice whether to go or not.
    I was once able to go.

    And "was once" == "used to be".

    So tear it up, Language Maestro... I'm still right.
  • campkev 2009-03-09 14:32
    EndlessWaves:
    campkev:
    A Nonny Mouse:

    "i could have gone" and "i was able to go" mean exactly the same thing


    Really? Would you ever say "I could have gone" about something you actually went to?


    I came to a junction in the maze, I could have gone either way but the force was strong at that time and guided me down the right path.


    Exactly, you COULD HAVE gone either way, but you didn't go both ways(not that there's anything wrong with that), you went ONE way.

    You would never say "I could have gone to the concert, so I left right after work," would you?
  • Spectre 2009-03-09 14:35
    Tsk, tsk. All those comments and nobody thought about using dynamically generated code to minimize the code size. Behold:


    set i 0

    foreach char {W T F {\u203d}} {
    lappend foreach $i
    lappend switch $i "puts -nonewline $char"
    incr i
    }

    set switch "switch \$i {$switch}"
    set foreach [list foreach i $foreach $switch]

    eval $foreach


    I won't tell you which language it is, because it should be immediately obvious. ;=]
  • campkev 2009-03-09 14:41
    Code Dependent:

    I'm sticking with "I used to be able to go."


    Sorry, but "used to be able to" != "was able to".

    "Yesterday, I was able to bench press 250 for the first time."
    "Yesterday, I used to be able to bench press 250 for the first time."
  • Anon 2009-03-09 14:47
    A Nonny Mouse:
    Someone You Know:
    campkev:
    Someone You Know:
    campkev:

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.


    I am surprised no one has yet suggested "I was able to go".


    Ladies and gentleman, we have a winner!


    Thank you.

    For the record, and since no one seems to have objected to this one yet, "I used to be able to go" is the imperfect tense, not the past tense.

    This is complicated by the fact that the words "I was able to go" could also be used for the imperfect tense.


    "i could have gone" and "i was able to go" mean exactly the same thing


    At risk of introducing anything beyond speculation to a WTF comment thread, here are some references:

    http://en.wikipedia.org/wiki/English_modal_auxiliary_verb
    http://en.wikipedia.org/wiki/English_grammar#Conditional_forms

    "I was able to go" is past tense. "I could have gone" is conditional perfect. It needs something else to go with it. "Did you go to the concert?" "Yes, I was able to go." "I could have gone, but I was too busy posting on TDWTF".

    "I could have gone" has the same meaning as "I would have been able go", which is very different from "I was able to go".

    And to the original question, "I could go" works just fine. "Could" is the past tense of "can". The fact that "I could go" is ALSO a present conditional just confuses things.

    Past:
    "Could you lift the desk by yourself when you moved yesterday?"
    "Yes, I could lift it. I'm done moving." [Yes I was able to lift it]

    Present conditional:
    "Could you lift the desk by yourself if I were sitting on it?"
    "Yes, I could lift it. I'm Superman, I don't even have to try". [Yes I would be able to lift it]

  • Someone You Know 2009-03-09 14:56
    Code Dependent:
    Someone You Know:
    For the record, and since no one seems to have objected to this one yet, "I used to be able to go" is the imperfect tense, not the past tense.

    This is complicated by the fact that the words "I was able to go" could also be used for the imperfect tense.
    Now you're really getting nitpicky.

    Once upon a time, I could go.
    In the past, I could have chosen to go.
    I once had the power of choice whether to go or not.
    I was once able to go.

    And "was once" == "used to be".

    So tear it up, Language Maestro... I'm still right.


    Well, if you view the difference between the imperfect tense and the past tense as "really nitpicky", that's fine — I'd probably agree with you — but that doesn't mean the difference doesn't exist.

    If you say "I used to able to go", you are saying that at one time you were able to go, but you no longer are able to go. That's the imperfect tense (a.k.a. "past continuous"). Logically it's a sort of special case of the past tense, which just says that at one time you were able to go, and doesn't say anything about what you can do now. The confusion stems partly from the fact that in the case of this particular verb, the plain past tense is hardly ever actually used by anyone.

    I would agree, though, that "I could go" is commonly used as the past tense of "I can go". I don't know if that's truly a correct usage or just a common misusage.
  • Anon 2009-03-09 14:59
    I'm afraid it actually seems to be about 1.25cm long
  • Anon 2009-03-09 15:00
    campkev:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.

    Using the same verification standard, I have verified that my ****** is 10 inches long.


    I'm afraid it actually seems to be about 1.25cm long
  • Jan 2009-03-09 15:00
    Since this is an important case, I've added a Facebook group for it: http://www.facebook.com/group.php?gid=56420033725.

    Please consider joining: it is important that this misuse is stopped.
  • Bernie 2009-03-09 15:06
    diaphanein:
    There are:
    7 while loops.
    25 for loops.
    27 nested switch statements.
    81 cases for those switch statements.
    261 if statements.
    123 else statements.

    And a partridge (family) in a pair of (depth-first) trees.
  • Buddy 2009-03-09 15:12
    I lived in an area quite intolerant of any outsiders. An outsider would be one or both of non-white or non-English/German origin. I had "mixed" parentage (one parent was French), but blue-eyed and blond, so I was acceptable.

    The students, yours truly excluded, would harass any French teachers to the point of quitting.

    One lesson was common sayings about one's health: <<mal à la tête>>, <<mal au ventre>>, <<mal aux dents>>, etc, most of which were immediately obvious. One saying though <<mal au coeur>> caused us trouble: heartsick?, heart attack?, heartburn?, until one doofus said "I have a hard-on", much laughter ensued, followed by rampant and uncontrolled chair squeaking, and no more work got done that day.
  • Code Dependent 2009-03-09 15:13
    Someone You Know:
    If you say "I used to able to go", you are saying that at one time you were able to go, but you no longer are able to go.
    I used to be able to benchpress 200; let's see if I still can.
    Someone You Know:
    I would agree, though, that "I could go" is commonly used as the past tense of "I can go". I don't know if that's truly a correct usage or just a common misusage.
    I see it as future: "I could go if I wanted to; but I don't want to, so I won't go."
  • Someone You Know 2009-03-09 15:31
    Code Dependent:

    I see it as future: "I could go if I wanted to; but I don't want to, so I won't go."


    As Anon pointed out above, that's a present conditional, which in the case of this verb happens to look the same.
  • Code Dependent 2009-03-09 15:38
    Someone You Know:
    As Anon pointed out above, that's a present conditional, which in the case of this verb happens to look the same.
    I excelled at English all through school, but that was a very long time ago, and I've had no need of the technical intricacies of that knowledge since. It's faded with disuse.

    I love good wordplay far more than formal correctness.
  • Someone You Know 2009-03-09 15:49
    Code Dependent:
    Someone You Know:
    As Anon pointed out above, that's a present conditional, which in the case of this verb happens to look the same.
    I excelled at English all through school, but that was a very long time ago, and I've had no need of the technical intricacies of that knowledge since. It's faded with disuse.

    I love good wordplay far more than formal correctness.


    I agree. I've never had any real need of those technical intricacies either, but I can't seem to actually get that stuff out of my head. I'd gladly replace it with something more interesting if I could; sometimes it's a shame that human brains don't work like hard drives.
  • Erzengel 2009-03-09 15:53
    This For-Case seems like a great idea... when paid by line. I'll have to remember it. ;)
  • My Name? 2009-03-09 15:58
    This method needs to be packaged up as wtf.dll utility pack to be downloaded by users.

    thedailywtf.com should start doing it for each of this super methods :)
  • Zapp Brannigan 2009-03-09 16:02
    I don't have .net. Last time I used VB was VB6. Is it still possible to concatenate strings with '+' and do mid(), left(), right() and format() still exist or have they been depreciated?
  • halcyon1234 2009-03-09 16:05
    m0ffx:
    Yeah, the verb 'can' is a bit weird. And English spelling is very oddball.

    But there's an awful lot that's SIMPLE about English.

    * Few tenses (compared to some languages).
    * Only one (modern) form of 'you'.
    * The only noun-verb agreement is singular vs plural. There's no need for noun-adjective agreement.
    * No 'gender' for inanimate objects.


    And you can verb the nouns, allowing you to redictionary any word you want!
  • Code Dependent 2009-03-09 16:05
    Someone You Know:
    If you say "I used to able to go", you are saying that at one time you were able to go, but you no longer are able to go.
    On this subject, I saw a really good example years ago on the 70's TV comedy show "The Jeffersons". If you're not a US resident you may not know that the show capitalized on the US racial tensions of that period. Two of the main characters were a young black man and his father who epitomized the "I'm black and I'm proud" mentality (actually, "satirized it" would be more correct).

    One episode dealt with an aging uncle who had retired from professional boxing to become a butler for a rich white family. The two regulars kept teasing and insinuating about him being an "Uncle Tom", with terms like "massah" and "bowing and scraping", until he finally had his fill of it, and rose up to his full height of about 6'5" and said, "Why, you young punk, I used to put away three like you before breakfast."

    Clearly meaning, "...and I still can."
  • Lunkwill 2009-03-09 16:08
    \begin{quotation} % This is just to add geekiness
    For Loop Liberation Front. We're the Liberation Front for For Loops! For Loop Liberation Front...Cawk.
    \end{quotation}
  • Lunkwill 2009-03-09 16:09
    [quote user="pscs"][quote user="ContraCorners"]Many languages don't have modal verbs, it's generally Germanic ones which do. Romantic languages change the verb form itself.[/quote]...into a valentine? :D

    [quote user="Buddy"]Technically, English doesn't have infinitives, most tenses, or even a grammar in the sense of inflected languages like Latin and old Greek (from which grammar terms were derived).[/quote]That's a pretty limited sense of "grammar" though as the same can be said of most of the world's languages.

    [quote user="Someone You Know"]For the record, and since no one seems to have objected to this one yet, "I used to be able to go" is the imperfect tense, not the past tense.[/quote]That's like saying "This code is not Visual Basic, it's VBA". "Imperfect tense" is the Latin term that makes little sense in English (or most other languages) because there's no 1:1 correspondence in their respective use. That's why this tense has been known as "past progressive" or "past continuous" for quite a while.

    Captcha: dolor :D
  • campkev 2009-03-09 16:17
    Code Dependent:
    Someone You Know:
    If you say "I used to able to go", you are saying that at one time you were able to go, but you no longer are able to go.
    On this subject, I saw a really good example years ago on the 70's TV comedy show "The Jeffersons". If you're not a US resident you may not know that the show capitalized on the US racial tensions of that period. Two of the main characters were a young black man and his father who epitomized the "I'm black and I'm proud" mentality (actually, "satirized it" would be more correct).

    One episode dealt with an aging uncle who had retired from professional boxing to become a butler for a rich white family. The two regulars kept teasing and insinuating about him being an "Uncle Tom", with terms like "massah" and "bowing and scraping", until he finally had his fill of it, and rose up to his full height of about 6'5" and said, "Why, you young punk, I used to put away three like you before breakfast."

    Clearly meaning, "...and I still can."


    So then this must be correct English as well. After all, they said it on the Jeffersons: "This here is the living area, where we does our living, and this is the dining area, where we does our dining, and this is the kitchen area..."
  • Steve 2009-03-09 16:22
    I blame the
    for
    union. Every job must be handled by one of the union members, or else.
  • Zork II 2009-03-09 16:39
    I'd like to say "WTF!!!!!!!!!" but have a major coffee-spat-over-keyboard problem to fix...

    thanks! You owe me a new keyboard!!!


    again!!
  • cconroy 2009-03-09 16:46
    Jeremy:
    SCB:
    But the present tense of "I was able to go" is "I am able to go", not "I can go".
    Explain that please.

    There isn't a difference between "I can verb" and "I am able to verb."


    How about "I can tuna fish" vs. "I am able to tune a fish"?
  • Code Dependent 2009-03-09 16:48
    campkev:
    So then this must be correct English as well. After all, they said it on the Jeffersons: "This here is the living area, where we does our living, and this is the dining area, where we does our dining, and this is the kitchen area..."
    Don't forget, "Feets: get movin'!"

    Satire.
  • grammar nazi 2009-03-09 16:55
    Well, I was going to stay out of this until now, but I have to comment on the discontinued use of "past perfect".

    I am nearing 27 years old, so I was in elementary school not that long ago, and I have never heard it any other way than "past perfect".

    Taking Latin in college finally cleared up the question that I never asked: what's so perfect about it? The Latin is the "per" prefix, roughly meaning "through", and "ficere", the verb meaning "to do or make". Hence, a past perfect verb is something that was done throughout, completely, and is not still happening. Likewise, a past imperfect verb would denote something that was started in the past, but was not done completely.

    Granted "past progressive" is easier for us to understand, but "past perfect" is more fun to say, especially knowing the true meaning of it.


    captcha: letatio
  • Gavin Olson 2009-03-09 17:13
    A for-case state machine is actually a legit way of designing a FSM using combinational logic and a counter; it leads to a pretty efficient chip count when using discrete logic components: http://en.wikipedia.org/wiki/Richard's_Controller

    There are a lot of applications where it's exceptional to not just proceed to the next state. This isn't one of those cases because it isn't even exceptional for the logic to not progress, it's impossible.
  • Darkstar 2009-03-09 17:33
    Perl style:

    for( 0 .. 3 ) {
    $out .= 'W' if( $_ == 0 );
    $out .= 'T' if( $_ == 1 );
    $out .= 'F' if( $_ == 2 );
    $out .= '?' if( $_ == 3 );
    }
    print $out;
  • Brian 2009-03-09 17:33
    It never fails to amaze me the horrendous measures taken by programmers (mostly Windows programmers) who've never been exposed to regular expressions.

    Regular expressions should be a core competency for absolutely any programmer anywhere.
  • Tyler W. Cox 2009-03-09 17:40
    I'm using practically the same regex s/(\d{3})(\d{3})(\d{4})/\1-\2-\3/ to format numbers xxx-xxx-xxxx for a legacy dialer from a multitude of sources and styles (xxx)xxx-xxx, xxxxxxxx, xxxxxxxxxx, x(xxx)xxxxxxx, ect. Because my procedures run on several million lines housed in legacy flat files I can definitely attest that regex is the way to go.
  • Brian 2009-03-09 17:46
    #!/usr/bin/env perl

    # Regular expressions are the staple tool of any seasoned programmer

    my $nicePhoneNumber = "";

    # Yucky phone number input
    my $phoneNumber = "abc123abcd456iewjf7890";

    # Strip non-digit characters
    $phoneNumber =~ s/[^\d]//og;

    # Format nicely
    if ($phoneNumber =~ /(\d{3})(\d{3})(\d{4})/) {
    $nicePhoneNumber = "($1) $2-$3";
    }

    # yields:
    # (123) 456-7890
    print "$nicePhoneNumber\n"
  • Code Dependent 2009-03-09 17:48
    grammar nazi:
    Granted "past progressive" is easier for us to understand, but "past perfect" is more fun to say, especially knowing the true meaning of it.
    I understood that such terminology went away by general public agreement after Joan Collins published her autobiography, Past Imperfect.
  • Code Dependent 2009-03-09 17:50
    Brian:
    It never fails to amaze me the horrendous measures taken by programmers (mostly Windows programmers) who've never been exposed to regular expressions.

    Regular expressions should be a core competency for absolutely any programmer anywhere.
    Agreed about Regex, but who gathered your statistics?
  • Lunkwill 2009-03-09 17:58
    halcyon1234:
    And you can verb the nouns, allowing you to redictionary any word you want!
    Verbing weirds language.

    grammar nazi:
    Well, I was going to stay out of this until now, but I have to comment on the discontinued use of "past perfect".

    I am nearing 27 years old, so I was in elementary school not that long ago, and I have never heard it any other way than "past perfect".
    It's imperfect that is now commonly called "past progressive", past perfect is a perfectly up to date term (which sounds like an oxymoron on a weird level)

    [simple] past: I went
    past progressive: I was going (or: I used to go)
    past perfect: I had gone
    past perfect progressive: I had been going
  • pink_fairy 2009-03-09 18:05
    WayneCollins:
    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


    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...
    Or, you could just write a state machine.

    Just sayin'.
  • Wonko The Sane 2009-03-09 18:10
    [quote]Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it[/quote/

    Now you have 2 options, as it is current - to go or not go, just because you can, doesn't mean you will...

    so the past tense is
    I went,
    or
    I didn't go...
  • Rich 2009-03-09 18:13
    WayneCollins:
    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


    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...

    Given that a for loop is just a while loop with a couple of built-in conveniences, why not go the whole hog and show us how to write a goto-case loop? Or if your beef is with the case statement, why not a self-modifying goto-goto loop? You couldn't possibly have any objection to that.
  • Rich 2009-03-09 18:20
    Wonko The Sane:
    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it


    Now you have 2 options, as it is current - to go or not go, just because you can, doesn't mean you will...

    so the past tense is
    I went,
    or
    I didn't go...


    Erm, what's wrong with "I could go"?
  • David 2009-03-09 18:23
    TRWTF is that the unformatted phone number is a string. if it was an integer, cound just use phoneNumber.ToString("(###) ###-####");
  • Wonko The Sane 2009-03-09 18:28
    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it


    How about a simpler question Do you want an Ice Cream ?

    Past tense...
    as statments of what happend
    You had an Ice Cream
    You did not have an Ice Cream
    or as a question
    Did you have an Ice Cream ?
  • Code Dependent 2009-03-09 18:28
    Rich:
    Wonko The Sane:
    so the past tense is
    I went,
    or
    I didn't go...


    Erm, what's wrong with "I could go"?
    You mean besides the fact that it's future, not past? Or do you have a time machine?

    "I could go last week... is that soon enough?
  • sw 2009-03-09 19:01
    He forgot to add 'on error resume next'
  • Jason 2009-03-09 19:14
    Clearly the result of management that is paying their developers based on the number of lines of code they write.
  • The Amazing X 2009-03-09 19:15
    cleanPhoneNumber?!?! But what if I wanted a dirtyPhoneNumber?
  • danixdefcon5 2009-03-09 19:18
    I'd love to see this code handling variable-length area codes, like the ones used in Mexico, the UK or some other countries...
  • PSWorx 2009-03-09 20:03
    Well, I don't know about Case, but I think I can rescue poor For.


    Public Shared Sub ApplyPhoneNumberFormattingRecursive(ByVal cleanPhoneNumber As String, ByVal i As Integer, ByVal formattedPhoneNumber As System.Text.StringBuilder)
    Select Case i
    Case 0
    formattedPhoneNumber.Append("(")
    Case 1
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(0))
    Case 2
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(1))
    Case 3
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(2))
    Case 4
    formattedPhoneNumber.Append(") ")
    Case 5
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(3))
    Case 6
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(4))
    Case 7
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(5))
    Case 8
    formattedPhoneNumber.Append("-")
    Case 9
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(6))
    Case 10
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(7))
    Case 11
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(8))
    Case 12
    formattedPhoneNumber.Append(cleanPhoneNumber.Chars(9))
    End Select
    If i < 12 Then
    ApplyPhoneNumberFormattingRecursive(cleanPhoneNumber, i + 1, formattedPhoneNumber)
    End If
    End Sub
  • Adrian Pavone 2009-03-09 20:46
    dpm:
    campkev:
    some schmoe:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
    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.


    Let me help you out
    dpm:
    <sarcasm>Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.</sarcasm>
    I beg your pardon! My claim that "the code sucks" was not sarcastic at all.


    Yeah, I thought the same thing. The sarcasm started on the "at least".
  • n 2009-03-09 21:53
    Akoi Meexx:
    My god, I remember when I thought VB was awesome. How stupid and naive I was in those days...

    Its not that VB is a bad language, its just its so easy to learn that any ninny can abuse it. HTML and javascript have the same problems.
  • David 2009-03-09 22:08
    Anon:

    "I was able to go" is past tense. "I could have gone" is conditional perfect. It needs something else to go with it. "Did you go to the concert?" "Yes, I was able to go." "I could have gone, but I was too busy posting on TDWTF".

    "I could have gone" has the same meaning as "I would have been able go", which is very different from "I was able to go".


    I could have read more, but after that I was unable to remain awake.
  • David 2009-03-09 22:24
    Code Dependent:
    Rich:
    Wonko The Sane:
    so the past tense is
    I went,
    or
    I didn't go...


    Erm, what's wrong with "I could go"?
    You mean besides the fact that it's future, not past? Or do you have a time machine?

    "I could go last week... is that soon enough?


    Douglas Adams:

    the main work to consult in this matter is Dr. Dan Streetmentioner's Time Traveler's Handbook of 1001 Tense Formations. It will tell you, for instance, how to describe something that was about to happen to you in the past before you avoided it by time-jumping forward two days in order to avoid it. The event will be described differently according to whether you are talking about it from the standpoint of your own natural time, from a time in the further future, or a time in the further past and is further complicated by the possibility of conducting conversations while you are actually traveling from one time to another with the intention of becoming your own mother or father.

    Most readers get as far as the Future Semiconditionally Modified Subinverted Plagal Past Subjunctive Intentional before giving up; and in fact in later editions of the book all the pages beyond this point have been left blank to save on printing costs.

    The Hitchhicker's Guide to the Galaxy skips lightly over this tangle of academic abstration, pausing only to note that the term "Future Perfect" has been abandoned since it was discovered not to be.
  • duckInferno 2009-03-09 22:26
    rohypnol:
    This is actually pretty clean, compared to some of my first coding attempts (which were in kindergarten)...

    Hello, Lyle!
  • Cooksey 2009-03-09 23:09
    The real WTF is whats not there...

    Feed this sucker bad f00d and it will roll right over and return garbage. Then the app will barf all the way to the can.

    There is no error checking visible, maybe it happens elsewhere, maybe not.

    More likely not. /hurl!
  • Chrismar035 2009-03-10 00:22
    I've never thought of using these two structures like this...it's a fine line
  • might have been able to go 2009-03-10 00:33
    You're confusing two different notions here: whether you wanted the ice cream, and whether you got it.

    I hold an ice cream in front of you. You want an ice cream. But I eat it instead. You WANTED an ice cream, but did not get one.

    Now let's try this again: I hold an ice cream in front of you. You want an ice cream. I give you the ice cream. You WANTED an ice cream, and then you got one.

    The same verb form applies regardless of whether you ate the ice cream or not. The question forms are analogous (do you want/did you want): they're about wanting, not about having.
  • SurturZ 2009-03-10 00:38
    If only it worked with the Windows TAPI!!
  • _TrXtR_ 2009-03-10 00:49
    That number is south african... and close by...
  • _TrXtR_ 2009-03-10 00:58
    Everything looks south african when you haven't had your coffee yet.

    When I started programming for a job, I was 18 and never formally studied. What I knew were friends, books. No internet.

    I wrote an application that generates a graph showing pressure inside a tunnel that's used for methane test explosions.

    I would with pride submit the code here if I had it. For with case and with more for and so forth... one vb file that did everything. Was really really bad.

    Anyways going to go on with my coffee and look at the wtf's over here
  • Andante 2009-03-10 01:11
    For a moment this had me tempted to reproduce it in assembly language.
  • jondr 2009-03-10 03:18
    EPE:
    Sorry, let me try again



    BAH! Mine goes up to eleven!



    Yeah, in binary it does.
  • boingle 2009-03-10 04:04
    How about

    ' I don't do VB, so excuse any errors
    Public Shared Function ApplyPhoneNumberFormatting(ByVal phoneNumber As String) As String
    Return phoneNumber
    End Function

    Formatting phone numbers is evil. Just because you format your numbers in the US, doesn't mean the majority of the world do!

    The only way to represent a phone number with international compliance is in a free form string.

    Thank you, I'll get my coat.
  • Watson 2009-03-10 04:15
    Back in .NET 1 times, I was porting into C# something from a language that had a "yield" construct for creating iterators. While these days I could just write


    foreach(Foo foo in this.fooCollection)
    if(foo is Something)
    yield return foo;


    "yield" wasn't in C# back then. The result instead was an enumerable class that had at its core (on first entry this._state==0):


    do
    {
    switch(this._state)
    {
    case 0:
    this._boss.fooCollection.Reset();
    this._state = 1;
    goto case 1;
    case 1:
    if(!this._boss.fooCollection.MoveNext())
    {
    this._state = 2;
    continue;
    }
    Foo foo = this._boss.fooCollection.Current;
    if(foo is Something)
    {
    this._current = foo;
    return true;
    }
    continue;
    case 2:
    return false;
    }
    } while(false);


    (Yes, I'm painfully aware that what csc would crank out is much hairier. No, I haven't had my coffee yet.)

    The Clayton's loop wouldn't be needed at all if "continue" did the obvious thing in switch statements to begin with.
  • firu 2009-03-10 05:14
    State machines are best implemented in hardware, thank you.

    module wtf(clk, rst, c);
    output [7:0] c;
    reg [7:0] c;
    input clk;
    input rst;
    reg [1:0] s;

    always @ (posedge clk or posedge rst)
    begin
    if (rst)
    c <= 8'b0;
    else
    case (s)
    2'd0 : c <= 8'd87; // 'W'
    2'd1 : c <= 8'd84; // 'T';
    2'd2 : c <= 8'd70; // 'F';
    2'd3 : c <= 8'd33; // '!';
    endcase
    end

    always @ (posedge clk or posedge rst)
    begin
    if (rst)
    s <= 2'b0;
    else
    s <= s + 2'b01;
    end

    endmodule



  • firu 2009-03-10 06:15
    I'm sorry, i forgot that Gray code may be better for the state encoding, please accept my corrected version and consider changing the original also to use gray code. This will reduce some of the power consumed by switching less bits.

    module wtf(clk, rst, c);
    output [7:0] c;
    reg [7:0] c;
    input clk;
    input rst;
    reg [1:0] s;

    always @ (posedge clk or posedge rst)
    begin
    if (rst)
    c[7:0] <= 8'b0;
    else
    case (s[1:0])
    2'b00 : c[7:0] <= 8'd87; // 'W'
    2'b01 : c[7:0] <= 8'd84; // 'T';
    2'b11 : c[7:0] <= 8'd70; // 'F';
    2'b10 : c[7:0] <= 8'd33; // '!';
    endcase
    end

    always @ (posedge clk or posedge rst)
    begin
    if (rst)
    s[1:0] <= 2'b0;
    else
    s[1:0] <= {s[0], ~s[1]};
    end

    endmodule

  • a right tool 2009-03-10 07:24
    Right tool for the right job:
    I use for loops for everything!
    I use for loops for everything!
    I use for loops for everything!
    I use for loops for everything!

    Even when wan is enough?
  • a right tool 2009-03-10 07:31
    m0ffx:
    Yeah, the verb 'can' is a bit weird. And English spelling is very oddball.

    But there's an awful lot that's SIMPLE about English.

    * Few tenses (compared to some languages).
    * Only one (modern) form of 'you'.
    * The only noun-verb agreement is singular vs plural. There's no need for noun-adjective agreement.
    * No 'gender' for inanimate objects.

    * Monosyllabic words are enough for normal, everyday life
    * No one can write it correctly
  • Maj najm 2009-03-10 08:11
    campkev:
    pscs:
    ricecake:
    SenTree:
    Arlen Cuss:
    'i' before 'e', except after 'c' ...
    weird ...
    Or sounding like 'a' as in "neighbor" or "weigh". Not the most leisurely of rhymes. I think I'm going to have a seizure.


    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).



    While I agree with you that the rule is almost useless, some of your examples are kind of WTF themselves. The rule is only meant for situations where the i and the e make a single sound. In science, society, deity and seeing, the i and the e are part of different syllables. Also, eider is Swedish, so you can hardly expect an English grammar rule to apply.


    eider is swedish? Sure dont look like it and I cant remember seeing it. Ejder otoh is a swedish word. ;)
  • Azd 2009-03-10 08:27
    My first code review comment for this would be:

    Case 4 is inconsistant, all the other cases append only one character, where as this appends 2. Please seperate into 2 cases.

    Andy
  • Trainee Programmer 2009-03-10 08:48
    Smash King:

    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.

    What's wrong with using a state machine to validate a phone number?
  • needless complexity 2009-03-10 08:49
    [quote user="pscs"][quote user="ContraCorners"]
    No, someone came up with "I could have gone", it just isn't right.[/quote]
    I have gone.[/quote]

    That's not right either.

    I could have gone might be past tense or might be conditional. So it might have been right.
    I might have gone is also possibly conditional.

    "I was able to go" is right, also "I had been able to go". You have to convert the modal verb 'can' to the 'to be able to' form. You have difficulty converting modal verbs (verbs which change the 'mode' of another verb) to past tense.


    [/quote]


    "I could go" is a perfectly valid past tense of "I can go".

    Today, I can go to the store.
    Three years ago, I could go to the store.

    Or to do it your way:

    Today, I am able to go to the store.
    Three years ago, I was able to go to the store.

    They both mean the same thing, and they are both perfectly correct.
  • campkev 2009-03-10 09:23
    [quote user="needless complexity"][quote user="pscs"][quote user="ContraCorners"]
    No, someone came up with "I could have gone", it just isn't right.[/quote]
    I have gone.[/quote]

    That's not right either.

    I could have gone might be past tense or might be conditional. So it might have been right.
    I might have gone is also possibly conditional.

    "I was able to go" is right, also "I had been able to go". You have to convert the modal verb 'can' to the 'to be able to' form. You have difficulty converting modal verbs (verbs which change the 'mode' of another verb) to past tense.


    [/quote]


    "I could go" is a perfectly valid past tense of "I can go".

    Today, I can go to the store.
    Three years ago, I could go to the store.

    Or to do it your way:

    Today, I am able to go to the store.
    Three years ago, I was able to go to the store.

    They both mean the same thing, and they are both perfectly correct.[/quote]

    It looks like I was wrong and that "I could go" is correct, but I've almost always heard it used in a way that implies that you are no longer able to.

    Which just adds more support to my supposition on the difficulty of English.
  • Someone You Know 2009-03-10 09:38
    campkev:


    It looks like I was wrong and that "I could go" is correct, but I've almost always heard it used in a way that implies that you are no longer able to.

    Which just adds more support to my supposition on the difficulty of English.


    At some point last night I realized I had forgotten how the hell this "I could go"/"I could have gone" debate started, and at that point I realized I needed to stop thinking about it and go kill some zombies. Left 4 Dead FTW!
  • icywindow 2009-03-10 10:46
    Well, since everyone else is doing it, Ruby!

    cleanNumber.each do { |n| formattedNumber.push(n) }
    formattedNumber.insert(0,"\(").insert(-5,"-").insert(4,"\)").join
  • arkal 2009-03-10 11:30
    You're my friend!
  • BBT 2009-03-10 11:30
    campkev:
    A Nonny Mouse:

    "i could have gone" and "i was able to go" mean exactly the same thing


    Really? Would you ever say "I could have gone" about something you actually went to?


    No. But i wouldn't say 'i was able to go' either. I'd say I WENT, for fuck's sake. Either way of phrasing it implies that you'll follow with 'but I didn't', and sounds dumb if you don't.
  • Code Dependent 2009-03-10 12:10
    David:
    the main work to consult in this matter is Dr. Dan Streetmentioner's Time Traveler's Handbook of 1001 Tense Formations. It will tell you, for instance, how to describe something that was about to happen to you in the past before you avoided it by time-jumping forward two days in order to avoid it.
    John Stein:
    A niche in time saves Stein.
    (With apologies to Isaac Asimov)
  • Botia 2009-03-10 12:21
    LOL, that's what it's all about! It truly makes you say WTF.
  • campkev 2009-03-10 12:36
    BBT:
    campkev:
    A Nonny Mouse:

    "i could have gone" and "i was able to go" mean exactly the same thing


    Really? Would you ever say "I could have gone" about something you actually went to?


    No. But i wouldn't say 'i was able to go' either. I'd say I WENT, for fuck's sake. Either way of phrasing it implies that you'll follow with 'but I didn't', and sounds dumb if you don't.


    ??? "Hey, did you make it to the concert Friday?" "Yeah, my boss let me off early, so I was able to go."
  • (Visitor) 2009-03-10 17:01
    phone "" 0 = ""
    phone s n = case n of {
    12 -> "(" ++ phone s 11;
    11 -> head s : phone (tail s) 10;
    10 -> head s : phone (tail s) 9;
    9 -> head s : phone (tail s) 8;
    8 -> ") " ++ phone s 7;
    7 -> head s : phone (tail s) 6;
    6 -> head s : phone (tail s) 5;
    5 -> head s : phone (tail s) 4;
    4 -> "-" ++ phone s 3;
    3 -> head s : phone (tail s) 2;
    2 -> head s : phone (tail s) 1;
    1 -> head s : phone (tail s) 0;
    _ -> ""}
  • BeSchT 2009-03-10 17:13
    Maj najm:

    eider is swedish? Sure dont look like it and I cant remember seeing it. Ejder otoh is a swedish word. ;)

    Is it?
    "Ejder zi lesn dem daily WTF solstu beser szrajbn programe!"
    Doesn't look swedish to me...
  • Lazy 2009-03-10 19:51
    ContraCorners:
    Pim:
    I want to see what the StripNonNumericCharacters function looks like!

    My guess would be something like this...

    Public Function StripNonNumericCharacters(ByVal sOrginalPhoneNumber as String) as String

    DIM sCleanPhoneNumber

    sCleanPhoneNumber = Replace(sOrginalPhoneNumber,"A","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"B","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"C","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"D","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"E","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"F","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"G","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"H","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"I","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"J","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"K","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"L","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"M","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"N","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"O","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"P","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"Q","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"R","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"S","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"T","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"U","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"V","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"W","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"X","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"Y","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"Z","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"a","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"b","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"c","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"d","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"e","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"f","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"g","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"h","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"i","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"j","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"k","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"l","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"m","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"n","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"o","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"p","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"q","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"r","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"s","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"t","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"u","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"v","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"w","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"x","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"y","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"z","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"`","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"~","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"!","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"@","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"#","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"$","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"%","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"^","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"&","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"*","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"(","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,")","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"_","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"-","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"+","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"=[","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"]","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"\","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"{","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"}","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"|","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,";","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,";","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"""","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"'","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,",.","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"/","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"<","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,">","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"?","")

    return sCleanPhoneNumber

    End Function


    I find this type of code in our legacy system on a daily basis :-(
  • Lazy 2009-03-10 20:27
    Oh, and...

    The past simple tense of "I can go" is "I could go." "I could have gone" is past perfect.

    Don't confuse syntax with semantics here. "I could go" can be interpreted as past indicative (I was able to do it yesterday, but now I can't) or second conditional (I could do it now, if i wanted to.) In both cases, the tense of the modal verb is the same.
  • Keybounce 2009-03-10 20:48
    Tempura:
    Bah, ugly!

    print ''.join(['W', 'T', 'F', '!'][i] for i in xrange(4))


    Might be a little out of practice (15 years), but I think this works:

    out(['W' | [ 'T' | [ 'F' | [ '?' | [] ] ] ] ] );

    P.s. Did I really read all of those comments and language discussions?
  • Eternal Density 2009-03-10 21:37

    Public Shared Function BuildComment() As String
    Dim oldComment As String
    Dim builtComment As New System.Text.StringBuilder
    oldComment = "me and this"

    For i = 0 To 14

    Select Case i
    Case 0
    builtComment.Append(oldComment.Chars(7))
    Case 1
    builtComment.Append(oldComment.Chars(8))
    Case 2
    builtComment.Append(oldComment.Chars(9))
    Case 3
    builtComment.Append(oldComment.Chars(10))
    Case 4
    builtComment.Append(oldComment.Chars(6))
    Case 5
    builtComment.Append(oldComment.Chars(9))
    Case 6
    builtComment.Append(oldComment.Chars(10))
    Case 7
    builtComment.Append(oldComment.Chars(2))
    Case 8
    builtComment.Append(oldComment.Chars(0))
    Case 9
    builtComment.Append(oldComment.Chars(3))
    Case 10
    builtComment.Append(oldComment.Chars(5))
    Case 11
    builtComment.Append(oldComment.Chars(4))
    Case 12
    builtComment.Append(oldComment.Chars(1))
    Case 13
    builtComment.Append(oldComment.Chars(10))
    Case 14
    builtComment.Append(oldComment.Chars(10))

    End Select

    Next

    Return builtComment.ToString

    End If

    End Function

  • izuka01 2009-03-10 21:37
    Torn from their mother at an early age, they toil, day and night without rest, as a cog in some oversized corporate wheel. They are forced, often brutally, to piecemeal together a hopefully valid telephone number from the leftovers of a processed string. They're tired, hungry, and begging for retirement to that place in the sky where all bloated code goes when it dies.

    ++ http://twitter.com/izuka01 - guyz plz follow me.. tnx ! ^^
    ` I will follow you too!

    ` izuka01.stumbleupon.com

    ` I have a blogs about mobile phones,
    ` I hope you like it guyz ^^

    visit my blogs:
    http://top-mobilephones.blogspot.com
    http://www.top-mobiles.tk
    http://www.topmobiles.tk
    http://www.jerome-sedurifa.tk

    RSS feeds: http://feedproxy.google.com/TopMobilePhones
  • oheso 2009-03-11 00:49
    Kermos:
    I swear, the next person that looks at me all wide eyed when they find out I study Japanese and asks me, in English nonetheless, "Isn't that too difficult?" is gonna be beaten senseless with a rubber chicken.


    muzukashii sugiru ja nai no?
  • oheso 2009-03-11 00:50
    8-'
  • oheso 2009-03-11 01:05
    Code Dependent:
    ... until he finally had his fill of it, and rose up to his full height of about 6'5" and said, "Why, you young punk, I used to put away three like you before breakfast."

    Clearly meaning, "...and I still can."


    Au contraire. It makes no representation whether he is currently able to or not. (I'm speaking only of the language now, and not of whatever facial expressions or mannerisms the actor was employing as I only vaguely remember that episode.)

    Furthermore, it is different from the example, which would be "I used to be able to put away three like you before breakfast." Clearly meaning that he no longer can.
  • VB 101 2009-03-11 07:11
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.

    Either that's sarcasm or I'm reading something different to you because only the length = 0 is checked.
  • Teh name!! 2009-03-11 08:29
    BeSchT:
    Maj najm:

    eider is swedish? Sure dont look like it and I cant remember seeing it. Ejder otoh is a swedish word. ;)

    Is it?
    "Ejder zi lesn dem daily WTF solstu beser szrajbn programe!"
    Doesn't look swedish to me...


    Well, if its a bird, then Im pretty sure its a swedish word. Otherwise, you've got another word that is spelled the exact same way. ;) And the fact that you also have a word spelled the exact same way doesnt really prevent the existance of a word with a completely different meaning being spelled the same way in a completely different language.

    And I just pointed out that eider is not a swedish word. The only correct use I can find of that spelling in swedish is the name of a german river. And I bet that its spelled the same way in german, so thus, its not swedish at all. ;)
  • drobnox 2009-03-11 11:11

    Common Lisp

    (loop for i from 0 to 2
    
    do (cond
    ((eq i 0)
    (format t "W"))
    ((eq i 1)
    (format t "T"))
    ((eq i 2)
    (format t "F"))))
  • Aaron 2009-03-11 14:00
    I'm not a computer programmer. I'm a controls engineer and I program in ladder logic. Sometimes I write crummy VB macros to do simple tasks for me.

    I don't usually get much out of the code snippets posted here because they tend to go over my head. This one made me chuckle!
  • J 2009-03-11 14:02
    I'd hate to see what this does with an international phone number.
  • PSWorx 2009-03-11 16:45
    Smash King:

    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.


    Right! The real way to validate a string is of course a Regex.

    Wait a minute...
  • Wyrd 2009-03-12 15:19
    Ok, this is really horrible code, but at least you can read it and figure out what it's supposed to do.

    Also, it looks to me like it will actually achieve the correct result. If so, then it's on par with bubble sort--except that bubble sort is obvious and wtf is only obvious if you're in the middle of stroke.

    --
    Furry cows moo and decompress.
  • Offf 2009-03-12 16:41
    I read the code. I burst in tears. Literally.
  • charonme 2009-03-13 04:15
    I want to see a haskell implementation
  • Iago 2009-03-14 13:27
    Kermos:
    Easy in Japanese though. :)

    行く - iku- go
    行った - itta - went
    The amusing thing is that this is an irregular verb in Japanese. If it had been a regular verb, the past tense would have been 行いた *iita.

    oheso:
    muzukashii sugiru ja nai no?
    「難しいすぎる」って日本語になるか。「難しすぎる」だろ、普通。
  • Obsidian 2009-03-17 21:12
    It's probably the work of an average programmer that was not used with Visual Basic. Guessing functions like MID$ and such from the first time is not obvious. However, "for" and "case" are written this way in many different languages. With the help of the auto-completion, this could explain a weird choice.
  • derp 2009-03-25 00:25
    Someone indulge a newbie and explain exactly what's wrong and what the better alternative is.

    Please?

    As far as I see, it loops through each position and assigns appends the character relating to that position.
    What's wrong with a for case loop?
  • you're missing the point 2009-03-25 01:28
    if its a fixed length state machine, why even run it in a loop at all? he could just code all 12 statements sequentially with no for and no select case.
  • derp 2009-03-25 13:56
    I think I misunderstood it.

    The case statement and for loop could just be removed and it would execute just the same, yes?

    I was thinking of where the condition for the case was dynamic, rather than just going 1, 2, 3
  • TadGhostal 2009-06-02 12:31
    Except there's no fall-thru in vb
    Vollhorst:

    For i = 0 To 12

    Select Case i
    Case 0
    Case 1
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(1))
    Case 2
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(2))
    Case 3
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(3))
    Case 4
    Case 5
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(5))
    Case 6
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(6))
    Case 7
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(7))
    Case 8
    Case 9
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(9))
    Case 10
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(10))
    Case 11
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(11))
    Case 12
    unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(12))

    End Select

    Next
    Obvious, isn't it?
  • C 2009-06-04 13:13
    I think this is simply supposed to be the "set next statement" in a crude IDE that offers only variable value watching and changing...
  • MF 2009-06-06 10:31
    pscs:
    ricecake:
    SenTree:
    Arlen Cuss:
    'i' before 'e', except after 'c' ...
    weird ...
    Or sounding like 'a' as in "neighbor" or "weigh". Not the most leisurely of rhymes. I think I'm going to have a seizure.


    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).



    i get your point. but i don't think i would ever spell 'seeing' as 'seieing' or would that be 'sieeing'. no wait 'siieeng'...