- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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)
Admin
"Hi. I can't find Mikael Åkerfeldt's name in your address book."
Admin
TRWTF is asking a graphic design house to build you a CMS.
Admin
Better safe than sorry!
Admin
Admin
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?
Admin
FTFY.
Admin
But they work with computers and websites, so it's all the same.</manager>
Admin
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!".
Admin
One would also assume that they're pulling all 120000 records from the database for each page displayed.
Admin
Ya, I had the same thought.
Admin
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!
Admin
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.
Admin
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...
Admin
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...
Admin
OPETH w00t!!!!!!!!!!
Admin
I love the way people "fix" the comments of ... oh I give up.
Admin
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.
Admin
Admin
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.
Admin
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.
Admin
Or letter #26, if you take in the fact that 'v' and 'w' are basically the same letter in swedish, only spelled differently.
Admin
This is the correct path.
Admin
Admin
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... )
Admin
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
?
Okay, I'm sure split() isn't that expensive, but it's a pet peeve.
Admin
And then handing it off to a network admin.
Admin
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?
Admin
TRWTF is PHP
I can't believe this hasn't been written yet.
Admin
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.
Admin
Admin
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.
Admin
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.
Admin
Or you could just break a string into its characters in the foreach loop
Admin
It was only deprecated as of php 5.3.0. Most of the world is still on 5.1 or 5.2.
Admin
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.
Admin
This is America you communist.
Admin
Want, want, want!
Admin
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.
Admin
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...
Admin
"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?"
Admin
Who hasn't done something like this?
Admin
Admin
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...
Admin
I don't see the WTF, this is America and they are making sure only American letters can be in the link. USA!
Admin
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.
Admin
If I were a cynic (which I am) I would wonder if the programmer gets kickbacks from a hardware manufacturer.
Admin
I'm in the USA, so Å becomes A.
CAPTCHA: "causa" - Å becomes A causa I said so.
Admin
I have Åkerfeldted your Mikael. Pray I don't Åkerfeldt it further.
Admin
Dangit, beat me to it.