- 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
Sorry - the Bible was NOT written in English... It was written in Hebrew (I think?).
Admin
No No. English is a language. Hebrew is a male teabag.
Admin
See, we Americans have letters that sound the same some of the time, but (at least barring some arguments regarding w/u and y/e) we make most of them do extra work so that none of them completely overlap. So we don't get this lovely concept of spelling a letter differently very often.
Admin
1.) It was clearly a joke 2.) The Old Testament was written primarily in Hebrew with a couple small sections in Aramaic. The New Testament was written in Greek although parts are also duplicated in Hebrew and Aramaic as well
Admin
I'm surprised no one else has mentioned this: the $output variable is not set prior to the if block that evaluates whether $list is an array. Which means if something called this function and fed it a variable that was not a list, it would return "Undefined variable error".
Not that it's the biggest WTF in the function, but if you don't know enough to initialize variables before you assign things to them, you probably should not be allowed to program anything to start with.
Admin
Admin
Admin
Um, guys? If you don't need the HAVING then you don't need the COUNT either:
SELECT DISTINCT SUBSTR(last_name, 1, 1) FROM customers
Admin
This all assumes the address book isn't stored in a text file, of course.
Admin
Admin
Admin
An Opeth reference on TDWTF? Awesome!
Admin
Your software doesn't meet the legal requirements where I live, but thanks for your offer anyway. Don't call us, we'll call you.
Admin
Seconded. Apart from ch in swedish and Spanish, there's
ij in Dutch (?) ll, rh and a few others in Welsh
Also last names starting with St and Sch had their own sections in German filing cabinets in the previous century. Paper address books still have separate pages because there are so many last names with S that separating St and Sch really helps.
Admin
But wouldn't this need a full scan through the database anyway?
OK, that'd be quicker than getting the whole data result set, and THEN going through it again, but wouldn't you be better either:
or
SELECT SUBSTR(last_name, 1, 1) FROM customers WHERE last_name like 'A%' UNION SELECT SUBSTR(last_name, 1, 1) FROM customers WHERE last_name like 'B%' etc
(if the database can optimize "LIKE 'A%'" to use an index)
or
SELECT SUBSTR(last_name, 1, 1) FROM customers WHERE last_name >='A' AND last_name <'B' UNION SELECT SUBSTR(last_name, 1, 1) FROM customers WHERE last_name >='B' AND last_name <'C' etc
(if the database can't optimize "LIKE 'A%'")
That way, it needs to do 26 navigations of the index tree to find the results, rather than a full scan of the whole data set. Of course, which of these is quicker would depend on lots of variables - probably need load testing.
But - doing it the original way was just dumb - if nothing else you're having to get the full data set from the database, just for this.
(If it was THAT important to do this, I think I'd probably use a separate letter/count table, with triggers to keep it updated)
Admin
To clarify, you want two clients who give you such an unimportant (i.e. inexpensive) workload that they don't care when it gets done? That kinda sucks; there's a reason this guy has a day job.
Admin
This will run pretty much instantly if there is an index on last_name, and requires no trigger to keep a letter count table updated. Locking on the letter table will probably be a performance killer if the customer table is large enough for it to be worth making the letter table in the first place.
Admin
He's listed under "Demon of the fall"
Admin
Admin
You'll have to explain the Opeth reference there..
Admin
I'm suprised nobody has pointed this out yet. What's really sad, is that the whole big $list array is not passed as a reference ( &$list ). That means PHP has made a copy of $list in memory before passing it to the function.
function getAlphabetList($list = null)
should be:
function getAlphabetList(&$list = array())
Never mind the other issues with the function, the problems begin with the function declaration.
Admin
ch in Swedish? What are you smoking?
Admin
It's just a naive implementation. TRWTF is that they couldn't spot this and some network admin had to be brought in. I bet there are profilers for php available. Hell, they could just print to html page how much method calls took time.