- 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
F1rst!
Admin
WTF
Admin
I believe I am being only slightly offtopic when I ask if anyone knows how to stop bleeding from the eyes.
Admin
Well, let's see... we could have a table in the database that lists the country codes and country names, but loops and DB access just slow down the system, so yeah, this is the best way to do it.
Not!
Admin
Talk about getting paid per line
Admin
I'm looking forward to the whole mess of "it looks OK to me, obviously this code is machine generated, so that's not a WTF" posts ....
Admin
Good thing this was written AFTER the fall of the Soviet Union. Although the thought of an application being taken down due to the formation of Kazakhstan amuses me for some reason.
Admin
Ummm...we get the point - don't you think you could have snipped a few more lines of the code? [:D]
Admin
<font size="4">Very impressive. Not using loops caused an infinite loop.
Sincerely,
Gene Wirchenko
</font>
Admin
I thought the same thing myself.
I was also disappointed to see that Trinidad and Tobago was snipped :-(
Admin
It looks OK to me, obviously this code is machine generated, so that's not a WTF
Admin
Well clearly the two problems were unrelated, the op was just illustrating how fragile the system really was. And hasn't somebody already yelled at you for signing your posts? Boilerplate sincerity is anything but.
Admin
Well, <OPTION value=US> should be <option value="US">, but at least he has the </OPTION>
Admin
God forbid somebody passes a null string into this method....
It would probably cause their network to go down...
Admin
If it wasn't machine generated at least we'll be sure that this "developer" will have a short career due to acute carpal tunnel syndrome.
Admin
Is this an example of the "loop unrolling" I've been hearing about?
Agreed. Is it added to the list yet?
Admin
I'd like to know where he got his ISO-3166 list of countries as practically all of the country codes shown aren't valid ISO-3166 codes.
At least he got the code for Bouvet Island correct. Shame no-one lives there!
Admin
Which brings up another thought: woe to the user that actually clicks on/pulls down this menu!
Admin
There's machine generated and machine generated... If you never see the code that's spit out by the machine (another issue) and you trust the generator (yet another), well, maybe. This looks like he used a Perl script to generate it and then pasted it in.
On the bright side, he might've kept the Perl script(s) around in case any new countries popped up.
Admin
No... Nooo! Nooooooooooooooooo!!!!!111!!!!omgWTF
Ze goggles, zey do nossink...
Admin
curious, how would you solve this?
SELECT all country codes from DB
LOOP through them and say
PRINT "<option val="+db_countryCode+(countryCode == db_countryCode ? " selected") + ">"+db_countryName+"</option>
can't see an efficient way to avoid the if statement num(countries_in_db) times.
Admin
If there's one thing the readers of this site are good at, it's beating the hell out of a joke. Next goal: kiss an actual girl.
Admin
Not to mention that the method is called "getCountry", which isn't what it does, and it uses a local variable to store the raw HTML, which is then put into a class-level string, which is then returned for some reason... I guess he's really worried about losing that variable.
--YY
Admin
you didn't get that.. he updated the *database* that code was old and broke following the update
Admin
Also observe Belgium can't be selected; Belarus appears twice instead:
<FONT face="Courier New" size=2> if(countryCode.equals("BE"))
countryString.append("<OPTION value="BE" selected>Belgium");
else
countryString.append("<OPTION value="BO">Belarus");</FONT>
This also suggests it's not machine-generated...
Admin
It's an ideal solution for an environment where database server is often unavailable. It also provides ultimate job security. So, hardcoding stuff is always a good idea any way you look at it.
Admin
> Well, <OPTION value=US> should be <option value="US">, but at least he has the </OPTION>
actually, no, he hasn't.. he has <option value=xx>XXX <option value=yy>YYY ...... </option>
Admin
Well, you could do...
Not uber pretty, but, it works!
Admin
ugh...
Well, you could do...
then (non-code lang specific)...
Not uber pretty, but, it works!
Admin
Oh! That's very common for machine to confuse the 2. See, machines, unlike us humans, are very stupid, and need to be told what to do. Machine can't necessary tell that BE = Belgium and Belarus are 2 different countries.
And that's also the reason why captcha never works the first time.
Admin
Chop your legs off. The bleeding from your eyes will subside shortly after.
Admin
Actually, most of those codes are valid--it's just that only about half of them are assigned to the correct place. Looks like the kind of thing I see when I try to sort two columns of a spreadsheet, and only one of them actually sorts.
Captcha: "platinum" as in, "I made Platinum with my airline flying around to retrieve all those misdirected packages...)
Admin
Canada, sob, was snipped. Second largest country in the world and it got snipped. It is not fair.
set ownoxgored off
(Though I live in the USA, I am Canadian.)
Sincerely,
Gene Wirchenko
Admin
The way I figure it, the less strain you put on the data tier, the better. As strain approaches zero, the awesomeness of your application approaches infinity.
Admin
That's why you are so polite, eh? Do you get to vote in Monday's election?
Admin
God, I HATE how wrong people can get writing something as html!!!
Every day in my work I get to work with html that has no doctype ("Oh, doctypes aren't required, so no need to use it... just takes up bandwidth!"), has multiple <head> sections ("I changed the title but it won't update, WHY!?"), and "hey, html needs no closing tags duz it?". :(
As such, I would not be suprised at all these days to see:
<SELECT name=dumbName>
**SNIP**
<OPTION>US
<OPTION>UK
<OPTION>ZA
**SNIP**
</SELECT>
Anyway, the real wtf here is that he used html for the drop down list rather than a flash object or java applet.
Admin
Yikes! It ate my html! Why can't it just htmlentity it? :(
Another attempt:
<SELECT>
<OPTION>US
<OPTION>UK
</SELECT>
Admin
How ugly. The correct way to do it is to create a database table which contains country codes and country names. Then, create an entity bean encapsulating those two fields. Use your favorite object-relational mapping tool to implement some sort of container-managed persistence, and create a session bean that you can use to get the list of country codes. Now, we might want to change the back-end country code implementation someday, so from there we need to create a CountryCodeConnector interface that returns objects that implement the CountryCodeProvider interface. After writing implementations for those two classes that use our beans, we simply plug our implementation for the connector into a service locating framework in our J2EE Server. Spring seems popular.
Then, when we want to create a drop-down list of countries for our users, all we need to do is user the framework to get the connector to get the provider to get the beans, copy the values over into Strut's "LabelValueBean"s. We'll stick all the LabelValueBeans into a list, attach it to the request in the action serving the form, and then we can simply use the html:optionsCollection tag to create the list!
For only a little more code then today's "WTF", we'll have a robust solution!
Admin
Why is there someone who has to try an solve these WTF's. Come on all WTF have a better solution. Just have a good laugh and enjoy the opportunity to take a few minutes to sigh and now that you are smarter than them.
*sigh* - Thanks to the programmer who made me feel better about myself today!!
Admin
I can't really come up with a worse way to do this. I'm trying...Maybe if you just put all the country names into one loooong string, then iterated through it one character at a time, stopping if you got to a country that matched the request? Meh. Doubt that would even work.
I thought I knew what conditional hell was, but this takes the cake. Jesus Christ, he could have at least used a case statement! I would have said an array, but an array is too good for this guy. I can't believe the monkey is working in Java as well...My god. Object oriented code, fool!
Admin
sweet I love when I have typo's!!!!
Admin
We have some garbage like this wtf in our old asp pages. In .NET it's much easier though: ddlvar.SelectedValue = "en_US";
Admin
do what now? ;)
Admin
StringBuffer countryString = new StringBuffer(5000);
I love this, but would kill to see the country that will max out this buffer.
Admin
LOL Good eye!
Admin
Nullpointeristan?
Admin
WOW! All these to create a simple drop-down list of countries! Will your implementation require a dedicated server?
Over engineering at its finest.
Admin
*A* dedicated server? What kind of pedestrian architecture is that? We'll need one server for the database, one server for the EJB's, and another for the web app. And that's if we're not going to have any redundancy. If this is an important application, we should probably have a cluster of some sort. Maybe a few, just to be safe.
Admin
He saved precious memory by eliminating the need for an iteration variable, simply genius!
Admin
Well, this is perfectly valid HTML so it could indeed be written that way.
In fact, but for the uppercasing, that's exactly how Anne van Kesteren's HTML code is written, and the guy (yes, it's a guy) is smart enough to know why he wrote it that way (you would probably be able to find his reasons somewhere in his archives)