• (cs)

    Can it be that the code was broken while it was prepared for this site? That doesn't even look remotely runnable (s <-> str, VALID_FOLDERS <-> FOLDERS, etc.).

  • Anonymous Tart (unregistered)

    Too close to reality for comfort :o

  • (cs)

    I sure am glad that this guy optimized it and didn't do somthing foolish like a switch case!

  • (cs)

    The real WTF is that the article isn't escaped properly, so the C# comments are parsed by my browser, and breaks the layout of the page.

  • Guybrush (unregistered)

    In Germany they speak deutsch, shortened to "deu" in the table.

  • nobody (unregistered)

    return s;

    What is s? Is it supposed to be str?

    Although 3 separate comparisons might be faster than copying the substring, but it would still allow urls like /duelish/foo/bar.html and match it with "deu"

  • (cs) in reply to Guybrush

    I'm not sure what the bigger wtf is - the code (if I can geuss what it's actually supposed to look like, as that snippet won't even compile), the fact that the HTML wasn't escaped so it broke the posting, or the fact that someone clearly didn't preview his submission before making it...

  • Luci (unregistered)

    Well, what happens id the URL is just "/" or something like "/x/"? ;)

    Captcha: digdug

  • Chris (unregistered) in reply to Guybrush

    To be pedantic, in Germany they speak German. Deutsch is German for German. Another w.t.f. is why the code doesn't consistently follow the convention of using the native name for a country/language. i.e. Spain should be 'Esp'.

  • mr blake (unregistered)

    i swear, i lost IQ points just reading this...

  • Bill Napier (unregistered)

    Easy Optimization: Use the 2 letter ISO language codes and save a comparison!

  • rien (unregistered) in reply to Guybrush
    Guybrush:
    In Germany they speak deutsch, shortened to "deu" in the table.

    you mean, in deutschland ? they speak german of course ! and when not speaking, they are driving big fast cars...

    Derrick Pallas:
    Apparently, they all speak different languages too.

    worst, they may speak different languages within the SAME country !

  • Fred (unregistered) in reply to Chris

    WTF 1: I'm quite sure that the built-in comparison function must do something similar, but without bugs. Why (badly) reinventing the wheel?

    WTF 2: Linear complexity. This would probably be faster with a map, especially when adding more languages (although for short collections, lists might outperform maps or hashtables).

    The guy who wrote the function (and the comment!) has an odd idea of what optimisation is...

    Captcha: Tesla. As tdwtf acts as a magnet on me?

  • joerbanno (unregistered) in reply to Guybrush
    Guybrush:
    In Germany they speak deutsch, shortened to "deu" in the table.

    Yeah and in the netherlands they speak nederlands thats why it is dut(ch)

  • Anonymous Tart (unregistered) in reply to joerbanno
    joerbanno:
    Guybrush:
    In Germany they speak deutsch, shortened to "deu" in the table.

    Yeah and in the netherlands they speak nederlands thats why it is dut(ch)

    It is almost certainly 'deu' because the developers are German. They aren't Dutch or Spanish, thats why those arent 'ned' or 'esp'.

    In our system we have uk (means English innit!), french, german, (sanity takes hold after here), es, jp, ko, br, etc

  • sanitarium (unregistered)

    With 1. such a small list, 2. short comparison (3 chars, one by one), and 3. modern cache size,

    it is really hard to determine if using a hashtable would even be faster. There is also no telling if the entries in FOLDER array is arranged from the most frequently requested to the least which would give speed advantage to the OP's code.

    So, I would not readily discount the efficiency of the OP's code. There are too many unclear variables.

  • PS (unregistered)

    What is Europe? And why don't they speak English like the rest of us?

  • (cs)

    coughHASHtablecough

    Oh, my. Sorry about that, I seem to have a frog in my throat.

  • lemming (unregistered)

    Why not use Resources?

    CAPTCHA: tesla, close but... serbia.

  • Jens (unregistered) in reply to PS
    PS:
    What is Europe? And why don't they speak English like the rest of us?

    Europe: The Swedish band, best known for "The Final Countdown". And yes, they do sing in English. ;)

    Btw. I'm European and don't even own a car... Not even a small one...

  • Marcin (unregistered)

    The real WTF is that they used C#.

  • Rabbi (unregistered) in reply to PS
    PS:
    What is Europe? And why don't they speak English like the rest of us?

    Europe is the little place on the far side of the pond where most of your ancestors came from (not counting the few native Americans that were allowed to survive and interbreed). It includes an insignificant island called England - the place English comes from

    As for English, we don' speak it like the rest of you because we speak it as it should be spoken!

  • Marcin (unregistered)

    Also, notwithstanding cache sizes, etc. this is still sub-optimal. The language codes should be processed by prefix - that is, it sufficient to find an e to know that the language is english, or once one sees a d, then there are only two other options.

    Alternatively, for these three-byte codes, they should be packed into ints, to do each comparison in a single machine instruction.

  • PS (unregistered) in reply to Jens
    Jens:
    PS:
    What is Europe? And why don't they speak English like the rest of us?

    Europe: The Swedish band, best known for "The Final Countdown". And yes, they do sing in English. ;)

    Ironic.. do do do do do do do do .....

    Btw. I'm European and don't even own a car... Not even a small one...

    So whay kind of bicycle do you own?

  • Anonymous (unregistered) in reply to modelnine

    Ack! And I thought the scheme used here where each locale has it's own column in a table was back-ass-wards.

    Actual (paraphrased) quote from one of the senior-senior devs - "It is easier to just add a new column to the existing table than fix things properly." Nevermind that once the new column is added to the table, the corresponding data object needs a new field and all the code that reads the localized strings from said data object needs to know about the new getter for the field and then to check for some new locale and return the appropriate string.

    Really, it's easier. And very WTF-worthy.

    CAPTCHA: sanitarium ... scans iPod ... bangs head on table

  • VC1 (unregistered) in reply to Marcin
    Marcin:
    The language codes should be processed by prefix - that is, it sufficient to find an e to know that the language is english, or once one sees a d, then there are only two other options.

    I think you've just discovered the binary search algorithm.

    Implementation is left as an exercise to the reader. There will be a quiz on Tuesday.

    CAPTCHA: vern [RIP Ernest P Worrel]

  • (cs) in reply to joerbanno
    joerbanno:
    Guybrush:
    In Germany they speak deutsch, shortened to "deu" in the table.

    Yeah and in the Netherlands they speak Nederlands thats why it is Dut(ch)

    Yeah and in Belgium they speak either (a sort of) Dutch or French, and in Switzerland they speak German, Italian or some other language I forgot, and so on. Look at the Europe-section of i.e. Asus, you'll see the problem ;) Lets call it double-dutch ;)

    And as far as I know, American English is just how British English was spoken 200 years ago ;)

  • Frederik (unregistered) in reply to PS
    PS:
    Jens:
    PS:
    What is Europe? And why don't they speak English like the rest of us?

    Btw. I'm European and don't even own a car... Not even a small one...

    So whay kind of bicycle do you own?

    Generally depends on what kind of bike the person who forgot to use his lock owned. Works pretty well.

  • Jens (unregistered) in reply to PS
    PS:
    Jens:
    PS:
    What is Europe? And why don't they speak English like the rest of us?

    Europe: The Swedish band, best known for "The Final Countdown". And yes, they do sing in English. ;)

    Ironic.. do do do do do do do do .....

    Btw. I'm European and don't even own a car... Not even a small one...

    So whay kind of bicycle do you own?

    trioBike, if you must know ;)

    CAPTCHA: ewww ... Bad code, no twinkie

  • JL (unregistered)

    I don't understand what the problem is... The code really is pretty close to optimal. If you assume that the URL's validity has already been checked (length >= 4) and that "return s" is really supposed to be "return str" and that "FOLDERS" is really "VALID_FOLDERS", I don't see anything wrong with the code.

    In a performance-critical application, it's perfectly reasonable to unroll the inner string comparision, saving a function call plus the math and object creation needed to extract the relevant substring from the URL. And using a hashmap may not be as efficient as a linear search over 11 values, considering that you'd also have to construct a substring, then find its hash in the hashmap.

    I assume they've already checked to see whether foreach (creating and destroying an iterator) is more efficient than using a for loop with an index variable. Really, I'm not sure it could be much more efficient without fully unrolling the loop to conditionals or case statements, collapsing common prefixes; the resulting code would be unreadable -- you'd want to write a code generator for it. And even that may be slower, depending on cache effects and branch prediction.

  • (cs)

    I don't know about the rest of you, but I for one speak American, where's the option for that?!

    </sarcasm>

    In all reality though, American English is so different these days, in pronunciation, slang, and meaning, that one could certainly consider it a whole language beyond the Queen's native tongue.

  • D-d-d-daaaaan (unregistered) in reply to Rabbi

    English?? you mean that weird little dialect of American?

    How quaint...

  • (cs) in reply to Anonymous Tart

    Well, except Dutch (which should be 'nld'), all of these are actually ISO language codes (ISO 639-3 if you care). Which are different from ISO country codes.

  • (cs)

    they work less and play more Optimization

    they drive tiny little cars. No need for big cars to drive around. And we also use a lot public transport ^^

    Apparently, they all speak different languages too. We do this just for the fun when foreigners are around, in fact we all speak alien fluently.

  • Pon (unregistered) in reply to mbvlist
    mbvlist:
    joerbanno:
    Guybrush:
    In Germany they speak deutsch, shortened to "deu" in the table.

    Yeah and in the Netherlands they speak Nederlands thats why it is Dut(ch)

    Yeah and in Belgium they speak either (a sort of) Dutch or French, and in Switzerland they speak German, Italian or some other language I forgot, and so on. Look at the Europe-section of i.e. Asus, you'll see the problem ;) Lets call it double-dutch ;)

    And as far as I know, American English is just how British English was spoken 200 years ago ;)

    Belgians speak Dutch. The Swiss have four official languages, including one called "Swiss-German".

    And no, American English is just English written by lazy people who don't like 'u's.

  • (cs) in reply to Guybrush
    Guybrush:
    In Germany they speak deutsch, shortened to "deu" in the table.

    Somehow I knew someone would reply with this. Thanks for the tip, Sherlock.

  • (cs) in reply to rien
    rien:
    worst, they may speak different languages within the SAME country !
    Welcome to Belgium. Here you can find people speaking dutch, others speaking french, another part speaking german. Not to mention unofficial local dialects that may sometimes be difficult to understand, the numerous different cultures in big cities and all languages spoken by various european governments representatives when they are around :)
  • B (unregistered) in reply to Pon
    Pon:
    Belgians speak Dutch.
    ... or French, or even German (not so many, but it's an official language altogether).

    FWIW, I'm a Belgian myself and I don't speak Dutch very well :)

  • Orion Adrian (unregistered)

    I'm gonna have to concur with the previous poster and say it feels like this is pretty optimal. Assuming the order of the countries is the order of the requests (it seems to be with the most common languages at the top assuming a German company) then unrolling the string comparison loop seems like a good idea.

    And given the small size of the collection hashtables seems like a much slower system seeing as how you have to still produce the hash which isn't a zero-cost exercise. What I would suggest to anyone who feels this is sub-optimal is to benchmark it yourself using primarily requests from the top 5 countries and than about 10% combined from the rest. I'll bet you the code presented will be faster.

  • Okayyy, hes in school ffs. (unregistered) in reply to Rabbi

    Bah. Europa. I prefer scandinavia. ;) Btw, there is a very small and odd language apart from nederlands. ;) dunno what its called in english though. Flamländska in swedish. Cool language.

  • Gordon (unregistered) in reply to Jens

    Europe: The Swedish band, best known for "The Final Countdown". And yes, they do sing in English. ;)

    'Europe' Swedish? You mean Finnish

  • (unregistered) in reply to Chris
    Chris:
    To be pedantic, in Germany they speak German. Deutsch is German for German. Another w.t.f. is why the code doesn't consistently follow the convention of using the native name for a country/language. i.e. Spain should be 'Esp'.

    or even 'Cas' for Castilian (just to separate it from American Spanish) :-)

  • Russ (unregistered)

    WTF are they doing this in the application? They should just have apache rewrite the url... something like this:

    RewriteCond %{REQUEST_URI} ^(/[^/])+)/(.)$ [NC] RewriteRule ^/(.)$ http://www.example.com/$2&lang=$1 [P,QSA]

    Now I haven't tested it, but you should probably see what I mean.

    Then again, most people running C# are running IIS, which is a WTF in itself.

  • KW (unregistered) in reply to VC1

    Radix search.

    CAPTCHA: e_www_. Yup.

  • Tom (unregistered) in reply to VC1
    VC1:
    Marcin:
    The language codes should be processed by prefix - that is, it sufficient to find an e to know that the language is english, or once one sees a d, then there are only two other options.

    I think you've just discovered the binary search algorithm.

    Implementation is left as an exercise to the reader. There will be a quiz on Tuesday.

    CAPTCHA: vern [RIP Ernest P Worrel]

    That's really not a binary search. At all. Arguably a [base-26]-ary search, but that's still a stretch.

  • gonville (unregistered) in reply to Pon

    The Swiss have four official languages (French, German, Italian and Romanche). Swiss-German isn't an "official" language in Switzerland, because there is no consensus on one version: there are as many different variants of Schwyzerdüütsch as there are valleys. Now don't get me started on the /other/ languages across Europe: Alsacien, Occitan, Piemontese , Catalan, Cornish.... For those interested, do a Google search on the languages that the Asterix comics are printed in. Aah! Internationali[s|z]ation is such fun :-)

  • mathew (unregistered)

    No, the REAL WTF is that the user's web browser already has a preference for what language they want to see the web site in, so the web server should just be using that.

  • Your Name (unregistered) in reply to mbvlist
    mbvlist:
    joerbanno:
    Guybrush:
    In Germany they speak deutsch, shortened to "deu" in the table.

    Yeah and in the Netherlands they speak Nederlands thats why it is Dut(ch)

    Yeah and in Belgium they speak either (a sort of) Dutch or French, and in Switzerland they speak German, Italian or some other language I forgot, and so on. Look at the Europe-section of i.e. Asus, you'll see the problem ;) Lets call it double-dutch ;)

    And in the Netherlands, there's also Frysian as a second official language (though only in the province of Fryslan), and low Saxon is recognized as a regional language by the EU - beside which you've got some people in Limburg speaking in a dialect that borders on being a separate language if it wasn't so much like German.

    Argh.

  • Rich (unregistered)

    Rather than questioning whether or not this is the best way to optimise this functionality, this is really yet another example of premature optimisation (y'know, root of all evil...). So this function gets called for EVERY page…and so, what? Lots of things get called once per page in a typical dynamic-content website, including some sort of database access. This will easily overshadow the performance gained here.

    Of course, maybe I'm wrong, maybe this app was properly profiled and the i18n WAS found to be the bottleneck. We can't tell. Yet, somehow, I doubt it… =)

  • snap2grid (unregistered) in reply to Rabbi
    It includes an insignificant island called England - the place English comes from
    England's an island now??? Scotland and Wales must have become detached somehow...

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

Log In or post as a guest

Replying to comment #117283:

« Return to Article