Comment On Laying the Foundation for i18n, Brick by Brick

In Europe, they do things a little bit differently. 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. Apparently, they all speak different languages too. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:02 • by modelnine
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.).

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:03 • by Anonymous Tart (unregistered)
Too close to reality for comfort :o

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:09 • by ssprencel
I sure am glad that this guy optimized it and didn't do somthing foolish like a switch case!

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:12 • by hardcorewizard
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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:15 • by Guybrush (unregistered)
In Germany they speak deutsch, shortened to "deu" in the table.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:18 • by 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"

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:19 • by Cloaked User
117241 in reply to 117237
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...

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:21 • by Luci (unregistered)
Well, what happens id the URL is just "/" or something like "/x/"? ;)

Captcha: digdug

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:25 • by Chris (unregistered)
117243 in reply to 117237
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'.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:28 • by mr blake (unregistered)
i swear, i lost IQ points just reading this...

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:29 • by Bill Napier (unregistered)
Easy Optimization: Use the 2 letter ISO language codes and save a comparison!

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:31 • by rien (unregistered)
117248 in reply to 117237
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 !

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:33 • by Fred (unregistered)
117249 in reply to 117243
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?

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:34 • by joerbanno (unregistered)
117251 in reply to 117237
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)

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:39 • by Anonymous Tart (unregistered)
117252 in reply to 117251
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

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:41 • by 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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:46 • by PS (unregistered)
What is Europe? And why don't they speak English like the rest of us?

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:54 • by Whiskey Tango Foxtrot? Over.
*cough*HASHtable*cough*

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

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 09:55 • by lemming (unregistered)
Why not use Resources?

CAPTCHA: tesla, close but... serbia.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:02 • by Jens (unregistered)
117265 in reply to 117255
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...

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:02 • by Marcin (unregistered)
The real WTF is that they used C#.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:03 • by Rabbi (unregistered)
117267 in reply to 117255
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!

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:10 • by 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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:13 • by PS (unregistered)
117270 in reply to 117265
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?

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:15 • by Anonymous (unregistered)
117271 in reply to 117230
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

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:18 • by VC1 (unregistered)
117273 in reply to 117269
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]

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:27 • by mbvlist
117275 in reply to 117251
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 ;)

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:27 • by Frederik (unregistered)
117277 in reply to 117270
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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:27 • by Jens (unregistered)
117278 in reply to 117270
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

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:28 • by 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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:28 • by nuclear_eclipse
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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:30 • by D-d-d-daaaaan (unregistered)
117281 in reply to 117267
English?? you mean that weird little dialect of American?


How quaint...

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:32 • by Skybert
117282 in reply to 117252
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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:33 • by tchize
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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:35 • by Pon (unregistered)
117284 in reply to 117275
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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:38 • by shadowman
117287 in reply to 117237
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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:38 • by tchize
117288 in reply to 117248
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 :)

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:43 • by B (unregistered)
117290 in reply to 117284
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 :)

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:43 • by 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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:45 • by Okayyy, hes in school ffs. (unregistered)
117292 in reply to 117267
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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:55 • by Gordon (unregistered)
117296 in reply to 117265
Europe: The Swedish band, best known for "The Final Countdown". And yes, they do sing in English. ;)

'Europe' Swedish? You mean Finnish

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:58 • by (unregistered)
117297 in reply to 117243
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) :-)

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:59 • by 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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 10:59 • by KW (unregistered)
117300 in reply to 117273
Radix search.

CAPTCHA: e_www_. Yup.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 11:03 • by Tom (unregistered)
117301 in reply to 117273
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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 11:05 • by gonville (unregistered)
117302 in reply to 117284
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 :-)

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 11:07 • by 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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 11:08 • by Your Name (unregistered)
117304 in reply to 117275
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.

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 11:08 • by 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… =)

Re: Laying the Foundation for i18n, Brick by Brick

2007-02-07 11:10 • by snap2grid (unregistered)
117306 in reply to 117267
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...
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment