• (cs)

    Dim First(5) First(0) = 5 ' F First(1) = 17 ' I First(2) = 8 ' R First(3) = 18 ' S First(4) = 19 ' T

  • sob, l (unregistered)

    TRWTF is no unicorn!

  • Doctor_of_ (unregistered)

    If only an episode of $(Children_tvShow) was bought to us by $array.

    Captcha: wisi. Wise Indeed.

  • meanwhile in scandinavia (unregistered)

    a bunch of people with names starting with Å, Ö and Ä are mightily upset

    ps: the "alphabet" doesn't have 26 letters...

  • moz (unregistered)

    The way it runs through the loop 27 times to catch the 26 cases is a nice touch.

    Although I can't help feeling that the code where it uses rptAlphabets could be even better than this. If it actually does, of course.

    And then I'm wondering what they'd do if they had more S names than will fit on one screen, but had no Z names at all.

  • MetaMonkey (unregistered)

    For switch is my favourite antipattern.

  • QJo (unregistered)

    TRWTF is clearly the fact that the indentation for case 24 is different from that for the other cases. Consistency is important, otherwise if third parties see the code they are likely to accuse you of unprofessionalism.

    The fact that the loop goes from 0 to 26 is a minor issue that ought to be fixable by adding a do-nothing "default" option to the case statement. I would not dare to change the index to 25 like some of you gung-ho code-monkeys for fear of breaking something.

    Apart from that, nothing to see here, move along, this code is perfectly cromulent.

  • QJo (unregistered) in reply to moz
    moz:
    The way it runs through the loop 27 times to catch the 26 cases is a nice touch.

    Although I can't help feeling that the code where it uses rptAlphabets could be even better than this. If it actually does, of course.

    And then I'm wondering what they'd do if they had more S names than will fit on one screen, but had no Z names at all.

    They could put your name in backwards, that would cure that.

  • JimmyCrackedCorn (unregistered)

    This code appears to be VB.Net, ADO.Net, and populating an ASP.Net repeater data control.

    Many directories also have entries for 'Mc', etc. which would only slightly complicate the loop that could be written. And it would be nice to test for letters that don't have entries.

  • QJo (unregistered)

    I am reminded of a tale my (poor, dead) mother told, about when she was working as a temporary clerical officer back in the days before computers when there was plenty of this sort of work about. A colleague of hers was tasked with arranging a large number of items into alphabetical order, so as to create an index. She did this by first creating a list of everything starting with A, then everything starting with B, then ... etc. She announced she had finished in a remarkably short time. Then the results of her work were inspected. It transpired that she did not actually understand that "alphabetical order" was a more technically involved concept than just "sorting into sets indexed by first letter". What was worse was that however hard dear mummy tried to explain the concept, the colleague in question could not understand what "alphabetical order" actually means.

    Oh how we laughed.

  • (cs)

    I can understand the reasons why a newbie might think that writing a constant array in order to iterate over it once and insert the contents into a data structure is a waste of space, but I can also understand that those reasons are WRONG.

    Not least, what do they think all those 'A', 'B' string/character literals are doing?

  • RFoxmich (unregistered)

    Hell I only read tdwtf for Remy's HTML comments anyway these days.

  • Architect (unregistered)

    This is a sterling example of hardened Enterprisey code. One never knows when the Alphabet Committee would introduce new letters and as such is beautifully future-proofed as well.

  • faoileag (unregistered) in reply to QJo
    QJo:
    What was worse was that however hard dear mummy tried to explain the concept, the colleague in question could not understand what "alphabetical order" actually means.
    She doesn't have to understand the concept. Ok, it would speed up things, but once the actual level of her incompetence is known, it would be up to her supervisor (your mother) to break down the task into sub-tasks of limited complexity.

    In this case, handing her back all cards of the letter 'A' with the words "now you sort these by the second letter in that word over there" would probably do the trick.

    You will then have to repeat this a few more times while keeping track of smaller and smaller packages of cards and at some point in the future you will have an alphabetically sorted set of cards.

    Of course getting a replacement co-worker would be smarter but what if you can't do that because the poor gal is the president's daughter?

  • faoileag (unregistered) in reply to Architect
    Architect:
    This is a sterling example of hardened Enterprisey code. One never knows when the Alphabet Committee would introduce new letters and as such is beautifully future-proofed as well.
    You are making fun of this, but please keep in mind that the Alphabet Committee is curently debating the introduction of an uppercase letter "ß" (or ß in HTML parlance), although there is not one single word that uses it (ok, I know it's all about "all capitals" but still).

    Who knows what else they might come up with?

  • Peter (unregistered) in reply to QJo
    QJo:
    I am reminded of a tale my (poor, dead) mother told, about when she was working as a temporary clerical officer back in the days before computers when there was plenty of this sort of work about. A colleague of hers was tasked with arranging a large number of items into alphabetical order, so as to create an index. She did this by first creating a list of everything starting with A, then everything starting with B, then ... etc.

    Apropos of nothing in particular, my (poor, dead) mummy taught us the alphabet song as children, since television had only recently been invented, and Kermit the Frog was not even a tadpole. After we had tried to imitate her, she would recite the alphabet backwards.

    This amazed us children, and when we asked her how and why she had learned to do this, she told us she had just felt like it. Only later did we learn that she had been involved in code breaking for the Navy in WWII (at age 25), which went a long way towards explaining her daily crossword puzzle habit as well...

    Miss you, Mum.

  • (cs) in reply to faoileag
    faoileag:
    Architect:
    This is a sterling example of hardened Enterprisey code. One never knows when the Alphabet Committee would introduce new letters and as such is beautifully future-proofed as well.
    You are making fun of this, but please keep in mind that the Alphabet Committee is curently debating the introduction of an uppercase letter "ß" (or ß in HTML parlance), although there is not one single word that uses it (ok, I know it's all about "all capitals" but still).

    Who knows what else they might come up with?

    How about generating the letter directory based on the results of a SQL query like:

    SELECT DISTINCT LEFT(name, 1) as letter FROM mydatabase ORDER BY letter
  • faoileag (unregistered)

    But apart from the already mentioned loop boundaries, and, of the course, the existence of said loop in the first place, where's the wtf?

    This is a lookup-table. I can easily envision other columns apart from "Alphabets". What, for instance, about column "ASCII":

    dr.Item("ID") = "C"
    dr.Item("ASCII") = "67"
    tempTable.Rows.Add(dr)
    

    Or "Etymology":

    dr.Item("ID") = "C"
    dr.Item("Etymology") = "The letter 'C' was originally developed ca. 400 b.c. by the Romans. It is blah, blah, blah..."
    tempTable.Rows.Add(dr)
    

    Who knows what the code does, that needs today's snippet?

  • Stephen (unregistered) in reply to Architect

    Also past proof as well. Should work with EBDIC (where 'A'-'Z' is not a contiguous run) as well as ASCII derived character sets.

  • faoileag (unregistered) in reply to MarkMc
    MarkMc:
    How about generating the letter directory based on the results of a SQL query like:
    SELECT DISTINCT LEFT(name, 1) as letter FROM mydatabase ORDER BY letter
    That way you get a list of all letters appearing as first letter of entries in the column "name" of database "mydatabase".

    Not much of a lookup-table here, I'm afraid. And with the possibility of being incomplete - what if people whose names start with e.g. "X" don't exist in your database?

  • MW (unregistered) in reply to Architect

    This actually happened just a few years ago in Sweden. The Swedish Academy formally decided to recognize W as an independent character (it was previously equivalent with V here in Sweden). So the 28 letter alphabet we used to have suddenly became 29 letters long.

  • (cs) in reply to faoileag
    faoileag:
    MarkMc:
    How about generating the letter directory based on the results of a SQL query like:
    SELECT DISTINCT LEFT(name, 1) as letter FROM mydatabase ORDER BY letter
    That way you get a list of all letters appearing as first letter of entries in the column "name" of database "mydatabase".

    Not much of a lookup-table here, I'm afraid. And with the possibility of being incomplete - what if people whose names start with e.g. "X" don't exist in your database?

    The idea was to generate a directory of letters that represent each distinct first letter of every entry in your database. This is to be a query executed every time, so if a name that starts with the letter 'X' appears, it is included when the query is executed.

  • faoileag (unregistered) in reply to MarkMc
    MarkMc:
    The idea was to generate a directory of letters that represent each distinct first letter of every entry in your database. This is to be a query executed every time, so if a name that starts with the letter 'X' appears, it is included when the query is executed.
    Ok, valid if you don't need to list letters for which there are no entries in the database as well.

    Yours:

    W
    Y
    

    Theirs:

    W
    X <!-- points to empty page -->
    Y
    
  • (cs) in reply to faoileag
    faoileag:
    MarkMc:
    The idea was to generate a directory of letters that represent each distinct first letter of every entry in your database. This is to be a query executed every time, so if a name that starts with the letter 'X' appears, it is included when the query is executed.
    Ok, valid if you don't need to list letters for which there are no entries in the database as well.

    Yours:

    W
    Y
    

    Theirs:

    W
    X <!-- points to empty page -->
    Y
    

    It also accounts for the names that start with letters that appear in the UTF-8 scheme (assuming your database stores that kind of data).

  • Krunt (unregistered)

    This code is not scalable. What happens when more letters are added to the alphabet in the future?

  • (cs)

    Who put the alphabet into order, eh? What criteria do you think they used?

  • RandomGuy (unregistered) in reply to eViLegion
    eViLegion:
    Who put the alphabet into order, eh? What criteria do you think they used?
    I thought it was common knowledge that the alphabet is ordered the way it is, to match that famous song.
  • anonymous (unregistered) in reply to faoileag
    faoileag:
    QJo:
    What was worse was that however hard dear mummy tried to explain the concept, the colleague in question could not understand what "alphabetical order" actually means.
    She doesn't have to understand the concept. Ok, it would speed up things, but once the actual level of her incompetence is known, it would be up to her supervisor (your mother) to break down the task into sub-tasks of limited complexity.

    In this case, handing her back all cards of the letter 'A' with the words "now you sort these by the second letter in that word over there" would probably do the trick.

    You will then have to repeat this a few more times while keeping track of smaller and smaller packages of cards and at some point in the future you will have an alphabetically sorted set of cards.

    Of course getting a replacement co-worker would be smarter but what if you can't do that because the poor gal is the president's daughter?

    A sort of a long-way-round version of bin sort. I like it!

  • EvilSnack (unregistered) in reply to faoileag
    faoileag:
    Architect:
    This is a sterling example of hardened Enterprisey code. One never knows when the Alphabet Committee would introduce new letters and as such is beautifully future-proofed as well.
    You are making fun of this, but please keep in mind that the Alphabet Committee is curently debating the introduction of an uppercase letter "ß" (or ß in HTML parlance), although there is not one single word that uses it (ok, I know it's all about "all capitals" but still).

    Who knows what else they might come up with?

    I am led to believe that when putting things in all caps (such as in newspaper headlines), this letter is replaced by 'SS', which makes it rather a nuisance when strings that are converted to all upper case, and then back, are compared to strings that were converted to all lower case. The replacement also changes the length of the string, which makes life less fun.

    This is one of the German language's many WTFeries, because 'ß' is derived from 'sz' (as can be seen from the HTML escape for it); but it is pronounced as if it were 'ss', and that's why the current substitution is made.

  • (cs) in reply to RandomGuy
    RandomGuy:
    eViLegion:
    Who put the alphabet into order, eh? What criteria do you think they used?
    I thought it was common knowledge that the alphabet is ordered the way it is, to match that famous song.

    I thought that was just coincidence.

  • give me teh codez (unregistered)

    I know how to fix this

    For i As Integer = 0 To 26
               Dim dr As DataRow
               dr = tempTable.NewRow
    
               Select Case i
                   Case 0
                       dr.Item("ID") = "A"
                       dr.Item("Alphabets") = "A"
                   Case 1
                       dr.Item("ID") = "B"
                       dr.Item("Alphabets") = "B"
                   Case 2
                       dr.Item("ID") = "C"
                       dr.Item("Alphabets") = "C"
                   Case 3
                       dr.Item("ID") = "D"
                       dr.Item("Alphabets") = "D"
                   ' SNIP … 
                   Case 24
                   	dr.Item("ID") = "Y"
                   	dr.Item("Alphabets") = "Y"
                   Case 25
                       dr.Item("ID") = "Z"
                       dr.Item("Alphabets") = "Z"
               End Select
    
               tempTable.Rows.Add(dr)
    
           Next
    

    amirite?

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered)

    You young whippersnappers can get off my lawn. When I was a kid, we used READ/DATA statements, and we loved it!

    Public Sub CreateAlphabets()   Dim tempTable As New DataTable   tempTable.Columns.Add("ID")   tempTable.Columns.Add("Alphabets")

      On Error Resume 11000   Restore 10000 10000 Data "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"

      Dim dr As DataRow   dr = tempTable.NewRow

      Read dr.Item("ID")   dr.Item("Alphabets") = dr.Item("ID")   tempTable.Rows.Add(dr)   Goto 10000

    11000   On Error Resume Next   Me.rptAlphabets.DataSource = tempTable   Me.rptAlphabets.DataBind() End Sub

    I even got rid of that pesky unneeded "i" variable, saving you 7 bytes of memory! That's 4 for a single-precision float, 2 for the variable name, and 1 for the variable type!

  • loopy (unregistered)
            private char[] Alpha()
            {
                //char alpha[] = new char[] {'A', 'B', 'C', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T','U', 'V', 'W', 'X', 'Y','Z' }
                int chrA = 65;
                char[] alpha = new char[26];
                for (int i = 0; i < 25; i++)
                {
                    alpha[i] = Convert.ToChar(chrA + i);
                }
    
                return alpha;
            }
    
  • Canadian Eh? (unregistered) in reply to Architect
    Architect:
    This is a sterling example of hardened Enterprisey code. One never knows when the Alphabet Committee would introduce new letters and as such is beautifully future-proofed as well.

    I live in Canada near the US border so we have both Zee and Zed in our alphabet!!!

  • (cs) in reply to ¯\(°_o)/¯ I DUNNO LOL
    ¯\(°_o)/¯ I DUNNO LOL:
    You young whippersnappers can get off my lawn. When I was a kid, we used READ/DATA statements, and we loved it!
    LOL That sure brings back memories!!! I'd forgotten what a horrid pile BASIC was!
  • JAPH (unregistered) in reply to Architect
    Architect:
    This is a sterling example of hardened Enterprisey code. One never knows when the Alphabet Committee would introduce new letters and as such is beautifully future-proofed as well.

    We have such issues in Hawaiian with the kahako and okina. We decided on the following collation: L1. Kahako andokina are ignored unless all other letters are the same L2. A vowel followed by a kahako follows the same vowel not followed by a kahako L3. A vowel preceded by an okina follows the same vowel not preceded by anokina

    Ohana</i> is therefore located under <i>O</i> and <i>Laie follows Laie

  • anonymouse (unregistered) in reply to Canadian Eh?

    interesting...I too live very close to the US border in Canada; I have found the same thing using both Zee and Zed for the last letter of the alphabet. As well as other interesting things like Soda or Pop etc...

    South West AB

  • Ramesh (unregistered)

    TRWTF is that they call letters 'alphabets'!

    http://phonetic-blog.blogspot.com/2010/07/alphabets.html

    CAPTCHA: secundum (wait a secundum!)

  • (cs) in reply to alo
    alo:
    Dim First(5) First(0) = 5 ' F First(1) = 17 ' I First(2) = 8 ' R First(3) = 18 ' S First(4) = 19 ' T

    This may be dependent on language, but it appears that you have an empty item in your array.

    Let me fix that for you:

    Dim First(4)
    First(0) = 5    ' F
    First(1) = 17   ' I
    First(2) = 8    ' R
    First(3) = 18   ' S
    First(4) = 19   ' T
    
  • TRWTF (unregistered)

    TRWTF is chubertdev and languages for which they are correct.

    Captcha: validus. chubertdev is not validus.

  • (cs) in reply to Peter
    Peter:

    Apropos of nothing in particular, my (poor, dead) mummy taught us the alphabet song as children, since television had only recently been invented, and Kermit the Frog was not even a tadpole. After we had tried to imitate her, she would recite the alphabet backwards.

    This amazed us children, and when we asked her how and why she had learned to do this, she told us she had just felt like it. Only later did we learn that she had been involved in code breaking for the Navy in WWII (at age 25), which went a long way towards explaining her daily crossword puzzle habit as well...

    Miss you, Mum.

    Nah... Your mom was a raging alcoholic that was well practiced in beating field sobriety tests. You left out the part where she stood on one leg, eyes closed, and touched her nose.

  • (cs) in reply to faoileag
    faoileag:
    QJo:
    What was worse was that however hard dear mummy tried to explain the concept, the colleague in question could not understand what "alphabetical order" actually means.
    She doesn't have to understand the concept. Ok, it would speed up things, but once the actual level of her incompetence is known, it would be up to her supervisor (your mother) to break down the task into sub-tasks of limited complexity.

    In this case, handing her back all cards of the letter 'A' with the words "now you sort these by the second letter in that word over there" would probably do the trick.

    You will then have to repeat this a few more times while keeping track of smaller and smaller packages of cards and at some point in the future you will have an alphabetically sorted set of cards.

    Of course getting a replacement co-worker would be smarter but what if you can't do that because the poor gal is the president's daughter?

    Bubblehead sort?

  • (cs) in reply to TRWTF
    TRWTF:
    TRWTF is chubertdev and languages for which they are correct.

    Captcha: validus. chubertdev is not validus.

    I'm glad that you gave examples to prove your point.

  • Jay (unregistered) in reply to meanwhile in scandinavia
    meanwhile in scandinavia:
    a bunch of people with names starting with Å, Ö and Ä are mightily upset

    ps: the "alphabet" doesn't have 26 letters...

    Well, but those people would be foreigners, so who cares?

  • (cs) in reply to loopy
    loopy:
            private char[] Alpha()
            {
                //char alpha[] = new char[] {'A', 'B', 'C', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T','U', 'V', 'W', 'X', 'Y','Z' }
                int chrA = 65;
                char[] alpha = new char[26];
                for (int i = 0; i < 26; i++)
                {
                    alpha[i] = Convert.ToChar(chrA + i);
                }
    
            return alpha;
        }
    

    FTFY

    All these 'off by one' errors do add up. Sometimes they can cancel out if you aren't careful.

  • Anachronda (unregistered) in reply to ¯\(°_o)/¯ I DUNNO LOL
    You young whippersnappers can get off my lawn. When I was a kid, we used READ/DATA statements, and we loved it!

    One of the teachers at my high school wrote an attendance program that kept the data in READ/DATA statements.

    Updating the data base? Well, this was a Commodore PET, which had full-screen editing. When you pressed ENTER, it would look in the screen memory to see what you had typed and execute it. So he updated the database by poking the updates in the screen memory and then poked an ENTER into the typeahead buffer. This would add the new DATA statements to the program, which the secretary would then save to cassette for use tomorrow.

    READ/DATA with a self-modifying BASIC program. And we loved it. Try to tell the kids that these days...

  • (cs)
    WHERE LEFT(FirstName, 1) COLLATE SQL_Latin1_General_Cp437_CI_AI = @Letter
    
  • (cs) in reply to RichP
    RichP:
    Nah... Your mom was a raging alcoholic that was well practiced in beating field sobriety tests. You left out the part where she stood on one leg, eyes closed, and touched her nose.

    I'd be more impressed if she stood on one eye, nose closed, and touched her leg.

  • anonymous (unregistered) in reply to ¯\(°_o)/¯ I DUNNO LOL
    ¯\(°_o)/¯ I DUNNO LOL:
    You young whippersnappers can get off my lawn. When I was a kid, we used READ/DATA statements, and we loved it!

    Public Sub CreateAlphabets()   Dim tempTable As New DataTable   tempTable.Columns.Add("ID")   tempTable.Columns.Add("Alphabets")

      On Error Resume 11000   Restore 10000 10000 Data "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"

      Dim dr As DataRow   dr = tempTable.NewRow

      Read dr.Item("ID")   dr.Item("Alphabets") = dr.Item("ID")   tempTable.Rows.Add(dr)   Goto 10000

    11000   On Error Resume Next   Me.rptAlphabets.DataSource = tempTable   Me.rptAlphabets.DataBind() End Sub

    I even got rid of that pesky unneeded "i" variable, saving you 7 bytes of memory!

    Yeah, but as I recall, the Data string isn't pre-tokenized; it's stored in memory as-is, which always seemed wasteful to me. That's 102 bytes of spaces, commas, and quotation marks to store 26 bytes of data.

    Not sure if your version would have supported it, but mine allowed you to omit the spaces and quotation marks, which made it a little better...

  • J (unregistered) in reply to QJo
    QJo:
    The fact that the loop goes from 0 to 26 is a minor issue that ought to be fixable by adding a do-nothing "default" option to the case statement.

    In all the languages I know, the case/switch/select construct has an implicit do-nothing default if a default is not given. Is VB different?

Leave a comment on “Today's Article is Brought to You by the Letters "WTF"”

Log In or post as a guest

Replying to comment #:

« Return to Article