• (cs) in reply to Code Dependent
    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.

  • (cs)

    This For-Case seems like a great idea... when paid by line. I'll have to remember it. ;)

  • My Name? (unregistered)

    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 (unregistered)

    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?

  • (cs) in reply to m0ffx
    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!

  • (cs) in reply to Someone You Know
    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 (unregistered) in reply to Buddy

    \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 (unregistered) in reply to campkev

    [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

  • (cs) in reply to Code Dependent
    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 (unregistered)

    I blame the

    for
    union. Every job must be handled by one of the union members, or else.

  • Zork II (unregistered)

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

  • (cs) in reply to Jeremy
    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"?

  • (cs) in reply to campkev
    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 (unregistered) in reply to Lunkwill

    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 (unregistered)

    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 (unregistered) in reply to keeper

    Perl style:

    for( 0 .. 3 ) { $out .= 'W' if( $_ == 0 ); $out .= 'T' if( $_ == 1 ); $out .= 'F' if( $_ == 2 ); $out .= '?' if( $_ == 3 ); } print $out;

  • Brian (unregistered)

    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 (unregistered) in reply to Kerio

    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 (unregistered)

    #!/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"

  • (cs) in reply to grammar nazi
    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.
  • (cs) in reply to Brian
    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 (unregistered) in reply to halcyon1234
    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

  • (cs) in reply to WayneCollins
    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 (unregistered)

    [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 (unregistered) in reply to WayneCollins
    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 (unregistered) in reply to Wonko The Sane
    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 (unregistered)

    TRWTF is that the unformatted phone number is a string. if it was an integer, cound just use phoneNumber.ToString("(###) ###-####");

  • Wonko The Sane (unregistered)
    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 ?

  • (cs) in reply to Rich
    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 (unregistered)

    He forgot to add 'on error resume next'

  • Jason (unregistered)

    Clearly the result of management that is paying their developers based on the number of lines of code they write.

  • The Amazing X (unregistered)

    cleanPhoneNumber?!?! But what if I wanted a dirtyPhoneNumber?

  • (cs)

    I'd love to see this code handling variable-length area codes, like the ones used in Mexico, the UK or some other countries...

  • (cs)

    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 (unregistered) in reply to dpm
    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 (unregistered) in reply to Akoi Meexx
    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 (unregistered) in reply to Anon
    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 (unregistered) in reply to Code Dependent
    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 (unregistered) in reply to rohypnol
    rohypnol:
    This is actually pretty clean, compared to some of my first coding attempts (which were in kindergarten)...
    Hello, Lyle!
  • Cooksey (unregistered)

    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 (unregistered)

    I've never thought of using these two structures like this...it's a fine line

  • might have been able to go (unregistered) in reply to Wonko The Sane

    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 (unregistered)

    If only it worked with the Windows TAPI!!

  • _TrXtR_ (unregistered)

    That number is south african... and close by...

  • _TrXtR_ (unregistered)

    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 (unregistered)

    For a moment this had me tempted to reproduce it in assembly language.

  • jondr (unregistered) in reply to EPE
    EPE:
    Sorry, let me try again

    BAH! Mine goes up to eleven!

    Yeah, in binary it does.

  • boingle (unregistered)

    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 (unregistered)

    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 (unregistered)

    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

Leave a comment on “Formatting a Phone Number - The Long Version”

Log In or post as a guest

Replying to comment #:

« Return to Article