• Anon (unregistered)

    F1rst!

  • WTF (unregistered) in reply to Anon

    WTF

  • (cs)

    I believe I am being only slightly offtopic when I ask if anyone knows how to stop bleeding from the eyes.

  • (cs)

    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!

  • Monday (unregistered)

    Talk about getting paid per line

  • (cs)

    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 ....


  • (cs)

    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.

  • ChiefCrazyTalk (unregistered) in reply to Sean

       Ummm...we get the point - don't you think you could have snipped a few more lines of the code? [:D]

  • (cs)
    Alex Papadimoulis:
    a while back, an edit to the configuration file to change the notification email address caused the system to bring down the email servers with a loop that became infinite when the config-file value didn't match the hard-coded value.

    public String getCountry(String countryCode) { StringBuffer countryString = new StringBuffer(5000); countryString.append("Please select country"); if(countryCode.equals("US")) countryString.append("United States"); else countryString.append("United States"); if(countryCode.equals("AF")) countryString.append("Afghanistan"); else countryString.append("Afghanistan"); if(countryCode.equals("AL")) countryString.append("Albania"); else countryString.append("Albania");

     
    <font size="4">Very impressive. Not using loops caused an infinite loop.

    Sincerely,

    Gene Wirchenko
    </font>
  • (cs) in reply to ChiefCrazyTalk
    Anonymous:
       Ummm...we get the point - don't you think you could have snipped a few more lines of the code? [:D]


    I thought the same thing myself.
    I was also disappointed to see that Trinidad and Tobago was snipped :-(
  • another guy (unregistered) in reply to Jeff S

    Jeff S:
    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 ....


     

    It looks OK to me, obviously this code is machine generated, so that's not a WTF

  • SweetFancyMoses (unregistered) in reply to Gene Wirchenko

    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.

  • (cs)

    Well, <OPTION value=US> should be <option value="US">, but at least he has the </OPTION>

  • (cs)

    God forbid somebody passes a null string into this method....

    It would probably cause their network to go down...

  • diaphanein (unregistered) in reply to Jeff S

    Jeff S:
    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 ....

    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.

  • (cs)

    Is this an example of the "loop unrolling" I've been hearing about?

    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 ....

    Agreed. Is it added to the list yet?

    • The goggles...
    • The real WTF here is...
    • Damn *%!@^ forum software!
    • This code tastes like burning...
    • Brillant!
    • He should have used isTrue in there somewhere...
    • etc.
  • (cs)

    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!

  • (cs) in reply to ChiefCrazyTalk

    Anonymous:
       Ummm...we get the point - don't you think you could have snipped a few more lines of the code? [:D]

    Which brings up another thought: woe to the user that actually clicks on/pulls down this menu!

  • (cs) in reply to diaphanein
    Anonymous:

    Jeff S:
    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 ....

    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.



    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.

  • Danimal (unregistered)

    No... Nooo! Nooooooooooooooooo!!!!!111!!!!omgWTF

    Ze goggles, zey do nossink...

  • (cs)

    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.

  • (cs) in reply to R.Flowers
    R.Flowers:

    Is this an example of the "loop unrolling" I've been hearing about?

    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 ....

    Agreed. Is it added to the list yet?

    • The goggles...
    • The real WTF here is...
    • Damn *%!@^ forum software!
    • This code tastes like burning...
    • Brillant!
    • He should have used isTrue in there somewhere...
    • etc.


    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.
  • YodaYid (unregistered) in reply to R.Flowers

    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

  • The doc (unregistered) in reply to Paul Abraham
    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.

    you didn't get that.. he updated the *database* that code was old and broke following the update
  • mark (unregistered) in reply to diaphanein

    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...

  • another guy (unregistered) in reply to s0be

    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.

  • The doc (unregistered) in reply to s0be

    > 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>

  • Gordo (unregistered) in reply to whitey

    Well, you could do...

    then (non-code lang specific)...
    <script>
    var f = document.forms[
    document.forms.length -1];
    var e = f.elements[f.elements.length -1];
    e.value = $countryCode$;
    </script>



    Not uber pretty, but, it works!

  • Gordo (unregistered) in reply to Gordo

    ugh...

    Well, you could do...

    &lt;code to generate the select...&gt;
    
    then (non-code lang specific)...
    &lt;script&gt;
    var f = document.forms[
    document.forms.length -1];
    var e = f.elements[f.elements.length -1];
    e.value = $countryCode$;
    &lt;/script&gt;


    Not uber pretty, but, it works!


  • another guy (unregistered) in reply to mark
    Anonymous:

    Also observe Belgium can't be selected; Belarus appears twice instead:

    <FONT face="Courier New" size=2>  if(countryCode.equals("BE"))
        countryString.append("<OPTION selected value="BE">Belgium");
      else
        countryString.append("<OPTION value="BO">Belarus");</FONT>

    This also suggests it's not machine-generated...

    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.

     

  • (cs) in reply to SeekerDarksteel
    SeekerDarksteel:
    I believe I am being only slightly offtopic when I ask if anyone knows how to stop bleeding from the eyes.


    Chop your legs off.  The bleeding from your eyes will subside shortly after.
  • silverpie (unregistered) in reply to Paul Abraham

    Paul Abraham:
    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!

    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...)

  • (cs) in reply to haveworld
    haveworld:
    Anonymous:
       Ummm...we get the point - don't you think you could have snipped a few more lines of the code? [:D]


    I thought the same thing myself.
    I was also disappointed to see that Trinidad and Tobago was snipped :-(


    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

  • (cs) in reply to another guy
    Anonymous:

    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.



    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.
  • (cs) in reply to Gene Wirchenko

    Gene Wirchenko:
    haveworld:
    Anonymous:
       Ummm...we get the point - don't you think you could have snipped a few more lines of the code? [:D]


    I thought the same thing myself.
    I was also disappointed to see that Trinidad and Tobago was snipped :-(


    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

    That's why you are so polite, eh? Do you get to vote in Monday's election?

  • JC (unregistered) in reply to The doc
    Anonymous:
    > Well, should be , but at least he has the

    actually, no, he hasn't.. he has XXX YYY ......


    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.
  • JC (unregistered) in reply to JC

    Yikes! It ate my html! Why can't it just htmlentity it? :(

    Another attempt:

    <SELECT>
     <OPTION>US
     <OPTION>UK
    </SELECT>

  • (cs)

    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!

  • (cs) in reply to whitey

    whitey:
    curious, how would you solve this?

    SELECT all country codes from DB
    LOOP through them and say
        PRINT "<OPTION ? + selected?) val="+db_countryCode+(countryCode&#13;&#10;== db_countryCode ? ">

    can't see an efficient way to avoid the if statement num(countries_in_db) times.

     

    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!!

  • (cs)

    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!

  • (cs) in reply to mrsticks1982
    mrsticks1982:

    whitey:
    curious, how would you solve this?

    SELECT all country codes from DB
    LOOP through them and say
        PRINT "<OPTION ? + selected?) val="+db_countryCode+(countryCode&#13;&#10;== db_countryCode ? ">

    can't see an efficient way to avoid the if statement num(countries_in_db) times.

    **EDITED**

    Why is there someone who has to try an solve these WTF's. Come on, all WTF's have a better solution. Just have a good laugh and enjoy the opportunity to take a few minutes to sigh and know that you are smarter than them.

    *sigh* - Thanks to the programmer who made me feel better about myself today!!

     

    sweet I love when I have typo's!!!!

  • (cs) in reply to whitey
    whitey:
    curious, how would you solve this?

    SELECT all country codes from DB
    LOOP through them and say
        PRINT ""+db_countryName+"

    can't see an efficient way to avoid the if statement num(countries_in_db) times.


    We have some garbage like this wtf in our old asp pages.  In .NET it's much easier though:  ddlvar.SelectedValue = "en_US";


  • (cs) in reply to Sean
    Sean:
    R.Flowers:

    Is this an example of the "loop unrolling" I've been hearing about?

    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 ....

    Agreed. Is it added to the list yet?

    • The goggles...
    • The real WTF here is...
    • Damn *%!@^ forum software!
    • This code tastes like burning...
    • Brillant!
    • He should have used isTrue in there somewhere...
    • etc.



    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.

     

    do what now? ;)

  • (cs)

    StringBuffer countryString = new StringBuffer(5000);

    I love this, but would kill to see the country that will max out this buffer.

     

  • ChiefCrazyTalk (unregistered) in reply to mark
    Anonymous:

    Also observe Belgium can't be selected; Belarus appears twice instead:

    <FONT face="Courier New" size=2>  if(countryCode.equals("BE"))
        countryString.append("<OPTION selected value="BE">Belgium");
      else
        countryString.append("<OPTION value="BO">Belarus");</FONT>

    This also suggests it's not machine-generated...

     

    LOL Good eye!

  • (cs) in reply to osp70
    osp70:

    StringBuffer countryString = new StringBuffer(5000);

    I love this, but would kill to see the country that will max out this buffer.

     



    Nullpointeristan?
  • Anonymous (unregistered) in reply to Suck My Lisp

    Suck My Lisp:
    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!

    WOW! All these to create a simple drop-down list of countries! Will your implementation require a dedicated server?

    Over engineering at its finest. 

  • (cs) in reply to Anonymous
    Anonymous:
    WOW! All these to create a simple drop-down list of countries! Will your implementation require a dedicated server?

    Over engineering at its finest. 

    *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.
  • Mr. Variable (unregistered)

    He saved precious memory by eliminating the need for an iteration variable, simply genius!

  • (cs) in reply to JC
    Anonymous:
    Yikes! It ate my html! Why can't it just htmlentity it? :(

    Another attempt:
    <SELECT>
    <OPTION>US
    <OPTION>UK
    </SELECT>

    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)

Leave a comment on “It's a Small World Afterall”

Log In or post as a guest

Replying to comment #:

« Return to Article