• An alternate explanation (unregistered)

    Easy performance enhancement: Add break; after $has_letter = true; add break;

    This will most likely speed up the code more then 100 times. (But it is still a wtf)

  • (cs)

    "Hi. I can't find Mikael Åkerfeldt's name in your address book."

  • Joe The Plumber (unregistered)

    TRWTF is asking a graphic design house to build you a CMS.

  • (cs)

    Better safe than sorry!

  • Thomas (unregistered) in reply to Joe The Plumber
    Joe The Plumber:
    TRWTF is asking a graphic design house to build you a CMS.
    This.
  • Asdf (unregistered)

    How about replacing substr(strtoupper($value),0,1) with strtoupper(substr($value,0,1)) ?

    I don't know anything about PHP, but 26 * 120000 of anything should take that much time?

  • (cs) in reply to Joe The Plumber
    Joe The Plumber:
    TRWTF is a graphic design house.

    FTFY.

  • (cs) in reply to Thomas
    Thomas:
    Joe The Plumber:
    TRWTF is asking a graphic design house to build you a CMS.
    This.

    But they work with computers and websites, so it's all the same.</manager>

  • Anonymous (unregistered)

    I love the way people "fix" the code in the comments. Guess what guys, you're on a website dedicated to the worst code ever produced. Your fixes are basically the equivalent of saying "I'm slightly smarter than a complete retard!".

  • (cs) in reply to Asdf
    I don't know anything about PHP, but 26 * 120000 of anything should take that much time?

    One would also assume that they're pulling all 120000 records from the database for each page displayed.

  • The Grenger (unregistered) in reply to Asdf
    Asdf:
    How about replacing substr(strtoupper($value),0,1) with strtoupper(substr($value,0,1)) ?

    I don't know anything about PHP, but 26 * 120000 of anything should take that much time?

    Ya, I had the same thought.

  • (cs) in reply to Anonymous
    Anonymous:
    I love the way people "fix" the code in the comments. Guess what guys, you're on a website dedicated to the worst code ever produced. Your fixes are basically the equivalent of saying "I'm slightly smarter than a complete retard!".

    I love the way people "fix" the comments in the comments. Guess what, you're on a website dedicated to the worst code ever produced, and you're trying to fix comments from people who are proudly proclaiming that they are slightly smarter than a complete retard!

  • AP² (unregistered)

    TRWTF is paying someone to build you a CMS, instead of installing one of the hundreds of existing FLOSS packages and an appropriate address book plugin.

  • qbolec (unregistered)

    When exactly does a string (substr) equal to integer (position)?

    if(substr(strtoupper($value),0,1) == strpos($letter,$value,1))

    http://pl2.php.net/manual/en/function.strpos.php http://pl2.php.net/manual/en/function.substr.php

    Actually quite often, since PHP has a lot of coertions, and strpos can return false occasionally, and letters [A-Z] are probably equal to false in such context. But if you happen to have the same letter twice in your name...

  • qbolec (unregistered)

    hmm actually the strpos takes (haystack, needle, offset), so chances are, that since the haystack = single letter, and offset == 1, then you always get false...

  • McMoo (unregistered) in reply to frits
    frits:
    "Hi. I can't find Mikael Åkerfeldt's name in your address book."

    OPETH w00t!!!!!!!!!!

  • ok enough already (unregistered) in reply to strictnein
    strictnein:
    Anonymous:
    I love the way people "fix" the code in the comments. Guess what guys, you're on a website dedicated to the worst code ever produced. Your fixes are basically the equivalent of saying "I'm slightly smarter than a complete retard!".

    I love the way people "fix" the comments in the comments. Guess what, you're on a website dedicated to the worst code ever produced, and you're trying to fix comments from people who are proudly proclaiming that they are slightly smarter than a complete retard!

    I love the way people "fix" the comments of ... oh I give up.

  • Count (unregistered) in reply to The Grenger

    26 letters in the alphabet 120 000 values in the list guess an avg of 8 letters per value (strtoupper())

    That's 25 million steps to determine if we should show 26 links on the page.

  • (cs) in reply to frits
    frits:
    "Hi. I can't find Mikael Åkerfeldt's name in your address book."
    Yeah, we don't care about accents, so it's listed under A.
  • (cs) in reply to An alternate explanation
    An alternate explanation:
    Easy performance enhancement: Add break; after $has_letter = true; add break;

    This will most likely speed up the code more then 100 times. (But it is still a wtf)

    That's true only if the list is unsorted. If the list is sorted then it will make it little more than twice as fast.

  • Cyp (unregistered) in reply to An alternate explanation

    If there's lots of names starting with all letters from 'A' to 'Z', and the list is unsorted, then likely a speedup with a factor of over 1000.

    If sorted, and 'A' to 'Z' are all represented, then it would likely speed up by a factor of about 2.

    If unsorted, but Zaphod Beeblebrox and all the other people starting with Z are missing, then likely a factor of about 26.

  • (cs) in reply to Airhead
    Airhead:
    frits:
    "Hi. I can't find Mikael Åkerfeldt's name in your address book."
    Yeah, we don't care about accents, so it's listed under A.
    Except it isn't an accent - it's letter #27 in the Swedish alphabet.

    Or letter #26, if you take in the fact that 'v' and 'w' are basically the same letter in swedish, only spelled differently.

  • Drew (unregistered) in reply to ok enough already
    ok enough already:
    I give up.

    This is the correct path.

  • jdw (unregistered) in reply to An alternate explanation
    An alternate explanation:
    Easy performance enhancement: Add break; after $has_letter = true; add break;

    This will most likely speed up the code more then 100 times. (But it is still a wtf)

    Thank you for this brilliant insight.

  • Svenson (unregistered) in reply to Airhead
    Airhead:
    frits:
    "Hi. I can't find Mikael Åkerfeldt's name in your address book."
    Yeah, we don't care about accents, so it's listed under A.

    That's not an accent. The last four letters of the Swedish alphabet are Z Å Ä Ö.

    ( In German, Ä Ö and Ü really are A, O, and U with diacritical marks and they sort exactly as the unaccented letters, which just goes to show how internationalization is a bitch... )

  • (cs)

    I know it's a very minor thing, but using split() for constant arrays annoys me. You only have to write it once, why not just say

    $alphabet = ['A', 'B', 'C', ..., 'Z'];
    

    ?

    Okay, I'm sure split() isn't that expensive, but it's a pet peeve.

  • Hogger (unregistered) in reply to Thomas
    Thomas:
    Joe The Plumber:
    TRWTF is asking a graphic design house to build you a CMS.
    This.

    And then handing it off to a network admin.

  • Ryan (unregistered)

    Or, you could just, you know, display all the letters and if you display an empty page because there are no people with names starting with that letter, who cares?

  • frits (unregistered)

    TRWTF is PHP

    I can't believe this hasn't been written yet.

  • (cs) in reply to frits

    select distinct upper(substring(columnName, 1, 1)) c from tableName order by c

    Addendum (2010-12-15 11:01):

    I'd probably just make them all links though even if they link to an empty page. Nobody would waste time clicking the link unless they were looking for a specific result anyways.

  • quarryman (unregistered) in reply to frits
    frits:
    TRWTF is PHP

    I can't believe this hasn't been written yet.

    It has, a tiresome multitude of times.

  • Christian (unregistered) in reply to toth

    Actually, split is a deprecated function. And yes, making an array notation to begin with would be smart. I'm always baffled at things like this because I try to imagine the thought process and the conversations behind it. I have a feeling the person had a simple list of just all letters at the top linked, and that's it, was proud of it too probably. Then came the manager and said well, you know, those letters that have no entries (out of 120k...) should not have a link. And I'm certain he thought that was something oh so simple and small and the developer would type it out in a minute or so. Now I imagine said developer sweating profusely at trying to come up with a solution and after several failed ones and maybe half a day or a full one and many tries and errors, they will have produced said example.

  • Ryan (unregistered) in reply to toth
    toth:
    I know it's a very minor thing, but using split() for constant arrays annoys me. You only have to write it once, why not just say
    $alphabet = ['A', 'B', 'C', ..., 'Z'];
    

    ?

    Okay, I'm sure split() isn't that expensive, but it's a pet peeve.

    Well, aside from the fact that you're exactly correct (though it's "array()" not "[]"), he should have used explode instead of split which would have been faster (though the difference in speed in this case is insignificant). Split has also been deprecated as of php 5.3.0, but the code was probably written before that.

  • Xenon Xavior (unregistered) in reply to toth
    toth:
    I know it's a very minor thing, but using split() for constant arrays annoys me. You only have to write it once, why not just say
    $alphabet = ['A', 'B', 'C', ..., 'Z'];
    

    ?

    Okay, I'm sure split() isn't that expensive, but it's a pet peeve.

    Or you could just break a string into its characters in the foreach loop

  • Ryan (unregistered) in reply to Christian
    Christian:
    Actually, split is a deprecated function. And yes, making an array notation to begin with would be smart. I'm always baffled at things like this because I try to imagine the thought process and the conversations behind it. I have a feeling the person had a simple list of just all letters at the top linked, and that's it, was proud of it too probably. Then came the manager and said well, you know, those letters that have no entries (out of 120k...) should not have a link. And I'm certain he thought that was something oh so simple and small and the developer would type it out in a minute or so. Now I imagine said developer sweating profusely at trying to come up with a solution and after several failed ones and maybe half a day or a full one and many tries and errors, they will have produced said example.

    It was only deprecated as of php 5.3.0. Most of the world is still on 5.1 or 5.2.

  • Ryan (unregistered) in reply to Xenon Xavior
    Xenon Xavior:
    toth:
    I know it's a very minor thing, but using split() for constant arrays annoys me. You only have to write it once, why not just say
    $alphabet = ['A', 'B', 'C', ..., 'Z'];
    

    ?

    Okay, I'm sure split() isn't that expensive, but it's a pet peeve.

    Or you could just break a string into its characters in the foreach loop

    When you use a string as the subject of a foreach loop in PHP, it actually treats each letter as an array element. "foreach ($alphabet as $letter)" would work just fine. This is probably the best solution, assuming someone wanted to keep the rest of the horrific code.

  • Thomas Jonathan Jackson (unregistered) in reply to frits
    frits:
    "Hi. I can't find Mikael Åkerfeldt's name in your address book."

    This is America you communist.

  • Jon (unregistered) in reply to Ryan
    Article:
    My clients (all two of them) assign me low-priority, get-it-done-whenever type projects...

    Want, want, want!

  • Dave (unregistered) in reply to frits

    OMG, I am working on an app that does almost the exact same thing, only in coldfusion not php, and they only have 80k records.

  • (cs)

    If only there was a piece of software that could intelligently sort and filter large amounts of data in an ordered way. Maybe something like, a database...

  • Spearhavoc! (unregistered)

    "This is kind of a problem you'd want to have, right? I mean, you have 120,000 address book records. That means 120,000 customers, right? Think of that loading time as a celebration of your success. Doesn't the coffee taste extra flavorful while the hourglass spins?"

  • frits (unregistered)

    Who hasn't done something like this?

  • Larry (unregistered) in reply to AP²
    AP²:
    TRWTF is paying someone to build you a CMS, instead of installing one of the hundreds of existing FLOSS packages and an appropriate address book plugin.
    But my pissant company is the mostest specialist unique-est thing in the world, and we need an invented here CMS to handle our brillant business methods. Plus, our graphic designers are the only people who can understand our brillants, and properly present us via colorful cartoons for our site.
  • Amy Extra (unregistered)

    15 years ago, our business folks used to hang out for hours in expensive New York restaurants with the ad agency's graphic designers, hammering out the critical details like exactly how many pixels wide the table column should be, or the precise color of the custom fonts rendered as blurry images in order to keep the page download time above 40 seconds. Then, after having spent millions on printed mockups, they'd bundle them all up and ship them to us peons in IT. Three days later they'd be calling about once an hour to see if we shoved the tape in the VCR yet, or whatever it is we do to make the magic stuff appear on their desktop TV-with-a-keyboard-you-never-touch, so they could brag to their high society friends that they too had a website nobody ever used.

    So, yeah, nothing much has changed lately...

  • (cs)

    I don't see the WTF, this is America and they are making sure only American letters can be in the link. USA!

  • (cs)

    It looks worse than it really is. What we don't know is the compiler is optimizing that loop for the six cores the server is using, so, no big deal.

  • (cs)

    If I were a cynic (which I am) I would wonder if the programmer gets kickbacks from a hardware manufacturer.

  • 'Murruhkan (unregistered) in reply to Svenson

    I'm in the USA, so Å becomes A.

    CAPTCHA: "causa" - Å becomes A causa I said so.

  • Darth Paula (unregistered)

    I have Åkerfeldted your Mikael. Pray I don't Åkerfeldt it further.

  • Gunslinger (unregistered) in reply to frits
    frits:
    TRWTF is PHP

    I can't believe this hasn't been written yet.

    Dangit, beat me to it.

Leave a comment on “Thorough Letter Checking”

Log In or post as a guest

Replying to comment #:

« Return to Article