• Sgt. Preston (unregistered) in reply to Grovesy
    Grovesy:
    Many of us do....
    Grovesy:
    Many of us do....
    Grovesy:
    Many of us do....
    Twitchy trigger finger?
  • Peter Lawrey (unregistered)

    A shorter version in Java.

      // A list of supported folder names
      public static final Set<String> VALID_FOLDERS = new HashSet<String>(Arrays.asList(
              "eng", // English
              "deu", // German
              "fra", // French
              "jpn", // Japanese
              "kor", // Korean
              "dan", // Danish
              "fin", // Finnish
              "swe", // Swedish
              "nor", // Norwegian
              "dut", // Dutch
              "spa"));
    
      // Returns the ISO language from URLs of the form "/lang/foo/bar.aspx".
      // NOTE: This gets called for EVERY request so it's as optimal as possible!
      public static String isoFromUrl (String url){
          return VALID_FOLDERS.contains(url) ? url : "";
      }
    
  • Grovesy (unregistered) in reply to Sgt. Preston
    Sgt. Preston:
    Grovesy:
    Many of us do....
    Grovesy:
    Many of us do....
    Grovesy:
    Many of us do....
    Twitchy trigger finger?

    freaky! swear I only hit that submit button once!

  • Nimrand (unregistered) in reply to Flash

    No it wouldn't. The point the original poster made was that the string comparison is insignificant compared to all the operations that a web server must perform to handle a SINGLE request. No matter how many concurrent requests you add, the total number of CPU cycles spent on the string comparison will STILL be insignificant compared to the total number of CPU cycles being spent to service all the requests. Sure, you can make your code more complex and less readable to get a 0.0001% increase in efficiency, but that isn't going to get you much even if the server is overloaded.

    CAPTCHA: onomatopoeia, are you kidding?

  • mh (unregistered)

    Has to be J# - the string array initialisation at the start is a giveaway.

  • (cs)

    The problem is that this C# function will always return empty string for URL's in the form specified in the comments. Given a URL '/lang/foo/bar.aspx' the 1'th, 2'nd, and 3'rd indexed characters in the string will always be 'l', 'a', and 'n' respectively. These will never match any of the values in the VALID_FOLDERS array and therefore the function will always return empty string, unless the parameter value is less than four characters in which case it will throw an IndexOutOfRangeException.

    Brent

  • Robbert (unregistered) in reply to BrentRockwood
    BrentRockwood:
    Given a URL '/lang/foo/bar.aspx' the 1'th, 2'nd, and 3'rd indexed characters in the string will always be 'l', 'a', and 'n' respectively. Brent

    This is off course the url given in the comment. Quite probably the URL will start with the server, giving the letters: 'ww.'

    Also, i18n is often not really a solution when it comes to preferred language. Example: I'm Dutch, my computer is installed in English, and I'm looking up information regarding SuSE (for example) while staying at a friend in southern Belgium (French language area).

    The language page I'll want to check is in German, because SuSE simply has more info in German. Other websites I might like to read in English, Dutch, French or ocasionally.

  • Anonymouse (unregistered)

    I think the function qualifies only in that it results in undefined behaviour (or error?) for strings shorter than three chars. In other aspects it looks like a legitimate attempt to do some input checking, by an inexperienced programmer who's nonetheless thinking exactly the right things (test your data before you use it so you can give a meaningful error message, and optimize where it matters). This function doesn't exactly radiate outright stupidity to me, just lack of experience/perspective. Not really fair game.

    Google's messy approaches are much more of a WTF if you ask me.

  • Phlip (unregistered) in reply to Robbert
    BrentRockwood:
    Given a URL '/lang/foo/bar.aspx' the 1'th, 2'nd, and 3'rd indexed characters in the string will always be 'l', 'a', and 'n' respectively. Brent
    Well, of course it will. "lang" isn't in the list of accepted languages, after all. "/eng/foo/bar.aspx" and "/deu/foo/bar.aspx" will work as expected, though.
    Robbert:
    This is off course the url given in the comment. Quite probably the URL will start with the server, giving the letters: 'ww.'
    The url as reported to the server starts with the first slash after the hostname. The hostname is sent to the server in a separate request header.
  • dr. Lecter (unregistered) in reply to Olius
    alex: From what I understand, it boils down to this: they work less and play more; when not working or playing, they drive tiny little cars.

    Dude, not cool.

    Not cool indeed, unless we point out that Americans learn less and declare wars on innocent people more, right? But we don't want to turn this into a pi**ing contest, do we?

    Olius:
    What's wrong with an american taking the piss out of Europeans? I'm from England: we do it all the time.

    What's wrong? You mean beside the fact that UK is a part of Europe (even though some might think they "know better")?

    Anyway, if you tend make fun of some country/continent, first learn how to make fun of YOUR country, it's not that hard.

  • hindsight (unregistered)

    PLEASE, TELL ME THERE'S SOMEONE OUT THERE STILL READING THIS

    THE CODE GOES:

    IF (S == "ENG") RETURN "ENG"; IF (S == "DEU") RETURN "DEU";

    ETC.

    FOR GOD'S SAKE THE SAME CODE CAN BE WRITTEN BY SAYING RETURN S;

    THAT IS THE WTF HERE. breathe

    (ok, so you need to take into account it not being one of the above and return an empty string instead. big deal. one line of code.)

    please tell me this is all some kind of big joke and everybody else did NOT miss this

  • Anonymous (unregistered)

    What language? My guess is either MUMPS or VB++...

  • Microoptimizer (unregistered)

    All the micro-optimizers so far are missing the obvious: using a sorted list and doing a binary instead of linear search would make a much bigger difference than calling substring vs nested if calls, etc. Not that it matters much, since as others said it's like pissing in a river.

Leave a comment on “Classics Week: Laying the Foundation for i18n, Brick by Brick”

Log In or post as a guest

Replying to comment #:

« Return to Article