Comment On Classics Week: Laying the Foundation for i18n, Brick by Brick

Laying the Foundation for i18n, Brick by Brick was originally published on February 07, 2007. [expand full text]
« PrevPage 1 | Page 2Next »

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 09:02 • by shambo
where is the spec? </old joke>

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 09:06 • by Arrrrrgh (unregistered)
Looks like C# to me....

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 09:37 • by Cable
looks like crap to me

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 09:43 • by rjn (unregistered)
135776 in reply to 135768
Actually, I think it's Java...

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 09:45 • by johnny (unregistered)
Ok so I've been pretty supportive during this week of classics, but I definitely wouldn't mind seeing an article from the early days and not from a few months ago. It doesn't take much to dig back a little bit further than early 2007.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 09:46 • by JC (unregistered)
135779 in reply to 135776
rjn:
Actually, I think it's Java...

Using .aspx pasges?

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 09:47 • by johnny (unregistered)
135780 in reply to 135776
rjn:
Actually, I think it's Java...


My guess is that it's C# because of the way the xml tags are in the comments to auto generate documentation. Javadoc uses a different syntax. That's just my guess though.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 09:50 • by null reference (unregistered)
135781 in reply to 135780
johnny:
rjn:
Actually, I think it's Java...


My guess is that it's C# because of the way the xml tags are in the comments to auto generate documentation. Javadoc uses a different syntax. That's just my guess though.


Definitely C# because of the xml comments.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 09:51 • by jmo21 (unregistered)
anything before this year would be too WhatTheFooky!!

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 09:55 • by burned (unregistered)
135783 in reply to 135776
rjn:
Actually, I think it's Java...

Lowercase S for string, XML single-line documentation, rather than two-star Java docs, "foreach" rather than "for", the use of "aspx" and static variable (string.Empty) in lowercase all mean it is not Java.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 09:58 • by Trinetra (unregistered)
Jesus! It's ... J# !!

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 10:00 • by H|B
Brick by brick, indeed.

So nested if's are the paramount of optimization?

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 10:13 • by Nomen est omen (unregistered)
So what's the WTF?

I hope it's not something as lame as "he should have used a hash table for speed". Because if the searched string is near the top of the list (i.e. most people access the "eng" pages), linear search can indeed be faster than extracting a three-character substring and calculating a hash checksum for it.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 10:13 • by Rob (unregistered)
135788 in reply to 135785
H|B:
Brick by brick, indeed.

So nested if's are the paramount of optimization?


... inside a loop!

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 10:23 • by max (unregistered)
This gets called for EVERY request so it's as optimal as possible!


Somehow, I don't think that's true....

Captcha: pointer. How apropo.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 10:25 • by Ametheus
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.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 10:29 • by Einsidler
Somehow, I think this makes sense to me... I guess if the inputted strings might be 'english' or 'danish', this would be the best way to do it. And since its going by url (if I've understood correctly) then it could catch some PICNICs.

Also, the real WTF is Worse Than Failure's own way of dealing with multiple languages.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 10:30 • by A.N. Consultant :p (unregistered)
The real WTF is that it's being checked every request. For the love of logic, why???

I think we've established that it's ASP.NET (the language is irrelevant).

If the end purpose is determining which language to present then this is a WTF because multiplle languages can be handled using the System.Globalization namespace.

If it's to handle differing products across multiple databases in different countries then we have to raise the other eyebrow and ask why this is also done by plumbing multiple copies of the same pages, unless they're running an http handler that does something very convoluted and worthy of the WTF code comp.

Perhaps this function was written by a student, Deployed by the lecturer who had set a task to optimize his p**s poor attempt at web app architecture.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 10:35 • by Thief^
135797 in reply to 135787
Nomen est omen:
So what's the WTF?

I hope it's not something as lame as "he should have used a hash table for speed". Because if the searched string is near the top of the list (i.e. most people access the "eng" pages), linear search can indeed be faster than extracting a three-character substring and calculating a hash checksum for it.


I'd guess that the wtf is the fact that there will be an identical copy of the entire site in each language folder, and that the script getting run (instead of a 404) should mean that the language code in the url is correct. Also the fact that it bothers checking the characters individually instead of just using a string compare.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 10:37 • by Ryde (unregistered)
135799 in reply to 135787
Nomen est omen:
So what's the WTF?

I hope it's not something as lame as "he should have used a hash table for speed". Because if the searched string is near the top of the list (i.e. most people access the "eng" pages), linear search can indeed be faster than extracting a three-character substring and calculating a hash checksum for it.


Well for one, he's checking character by character when you can just compare strings in C#. Those if statements could be replaced with a simple url.SubString(1, 3) == str.

But the REAL wtf is that C# and ASP.Net has a framework for dealing with globalization. It uses resource files, and will swap in the correct localized resource file based on your browser's language and location. He's ignoring that and doing his own home-brew solution.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 10:39 • by Nomen est omen (unregistered)
135800 in reply to 135794
The real WTF is that it's being checked every request. For the love of logic, why???


Wouldn't you want to verify the validity of every request?

If the end purpose is determining which language to present then this is a WTF because multiplle languages can be handled using the System.Globalization namespace.


My primary language is English. I wouldn't want web sites to look at my browser settings to determine my preferred language. Some sites have fabulously sucky translation... I want to select on a site-by-site basis.

This is even more important when I go in a web cafe in a foreign country. Try to use google abroad one day; how's your Korean...?

Country != preferred language; browser's idea of preferred language != preferred language. Those little flags at the top of web sites are really a nice way of handling i18n. A lot of web frameworks get this wrong.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 10:50 • by Nomen est omen (unregistered)
135801 in reply to 135799
[quote]Well for one, he's checking character by character when you can just compare strings in C#. Those if statements could be replaced with a simple url.SubString(1, 3) == str.[/code]
That is likely to be a tiny bit slower, due to creating an extra object. Although it is questionable whether all this micro-optimization is really worth it in the first place. Perhaps, after some measurement, one could conclude that subString() would be quite sufficient. Not really WTF-grade stuff though...

As to globalization frameworks; most of those tend to suck. Speaking both as a www user and a coder. Many are also single-language or single-platform "solutions". E.g. resource files can get a pain in the neck when you have to translate pieces of text out of the context in which they appear in the HTML file. Been there, done that.

Maybe Windows' way of doing things would have worked in this case. Or maybe not. The WTF itself doesn't really show there is a WTF here, other than probably the poster being WTFishly arrogant in thinking that hash tables are "of course faster, what a n00b the guy who wrote the loop must have been".

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 10:52 • by Nomen est omen (unregistered)
135802 in reply to 135800
Two posts earlier I wrote: "My primary language is English." The post makes a bit more sense if you know I meant to write "My primary language is not English." :-)

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 11:16 • by Uld (unregistered)
hey dude, "deu" stands for deutsch which means german in... german and certainly not "deulish".

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 11:34 • by dibbler (unregistered)
I have no problem with the three nested loops, which will be faster than a string comparison.

However, what if there is a file called (say)

/deutronomy/data.htm

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 11:34 • by The MAZZTer
Uld: Alex knows this, he's just being silly.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 11:56 • by a. (unregistered)
[quote}

[quote]Well for one, he's checking character by character when you can just compare strings in C#. Those if statements could be replaced with a simple url.SubString(1, 3) == str.[/quote]

That is likely to be a tiny bit slower, due to creating an extra object.
[/quote]

Just to be a nitpicker here... when you access the characters of the string by index, it will create a new char array based on the string from which the indexed character will be returned, so no, both are suboptimal.

If you are in .NET 2, do a String.Compare(string1, string2, StringComparison.OrdinalIgnoreCase), which will be the fastest way. (There is no need to du linguistically correct comparison on two url-s)

And in .NET 1.x you can use String.Compare(strin1, string2, true) indicating that you need a case insensitive ordinal comparison.

The REAL WTF

2007-05-10 12:33 • by Peter Davis (unregistered)
Is that it doesn't verify the length of the string.

It should check that str[4] == '/', or something.

Otherwise /lang/engXXX/foo.aspx passes and this validation is worthless!

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 12:33 • by Ben (unregistered)
Please believe me that I don't say this lightly, but you people are idiots. The Real WTF is that this function does nothing useful. It examines a substring of the URL and returns it iif that substring is found in an array of substrings. But since there's no other data attached to the array, actually using the language code for anything would entail another lookup (at which point an invalid language code could be caught). The Real WTF, in other words, is that twenty lines of "cleverness" is being used as a substitute for substr. And then that dozens of soi-disant gurus will take that code snippet and argue about for-loops.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 12:34 • by Peter Davis (unregistered)
135836 in reply to 135834
And furthermore, the URL "/e" fails with an IndexOutOfBoundsException (or whatever it is in C#).

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 12:34 • by Gilbert (unregistered)
The *real* WTF is that it's written in ENGLISH.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 12:38 • by maweki
135838 in reply to 135809
hey dude, "deu" stands for deutsch which means german in... german and certainly not "deulish".


As we pointed out when this WTF was shown first time. Obviously no one was able to read any comments of the reposted WTFs. Would have been really much work, when you're not writing them new.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 12:43 • by Bezalel (unregistered)
135840 in reply to 135809
actually DEU or GER both stand for German, the ISO 639-2 language codes translate to English. The reason that German has an additional code because the ISO 639-1 codes translated to the target language and GER is not a logical succesor to DE.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 13:18 • by sas
iGoogle's i18n is ridiculously wrong. I can understand using the local language as a first guess. But you must sign-in to ig, so why isn't my preferred language used then instead of the local one?

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 13:25 • by redds
All we have to critique is the actual code segment shown... we don’t know enough about the app to decide if using the URL to distinguish language was a good idea or not. The site may be using URL virtualization and the .NET localization and globalization techniques are not always the right way to go.

The only WTF I can see in the code is that the developer thought it actually mattered to optimize this block simply because it would be called for each request. He was wrong, and demonstrates that he utterly failed to understand the environment in which his code would operate.

And the other WTF is that so many people in these comments commenced to make the same mistake and start arguing if String.Compare() or Substring() or whatever else was a faster means of comparing the URL to the known languages than the nested if statements the initial developer used. That is the exact same mistake that lead the initial developer to write this junk in the first place.

It DOES NOT matter how you compare the strings!

This gets called once per REQUEST. If you look at the amount of work ASP.NET (or any server side web platform) performs on each request you'd quickly see that optimizing a simple match between a single string and a finite (and small) list of possible values is very much like pissing in a river and worrying that you might be causing a flood downstream. The original developer wasted an enormous amount of time (failing) to optimize something that won't have any appreciable impact on performance --that is the WTF here.


Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 13:44 • by snqow (unregistered)
The way I see, globalization frameworks should work like this:

1) check user cookie. If he has set some specific language, use it
2) nothin' in the cookies? then ask the browser
3) figure by the ip? (optional)
4) all failed? well then, fall back to app's native language

Anyway, the top-left/right language flags should STILL be available if the user would rather read the site in another language.

CAPTCHA: paint. Insert a witty remark here.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 13:46 • by Flash (unregistered)
135873 in reply to 135859
Yeah, but if 100000 people were pissing in the river at the same time, it would start to become an issue.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 14:40 • by Anonymous coward (unregistered)
135892 in reply to 135776
rjn:
Actually, I think it's Java...
Did Java gain the foreach keyword recently?

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 14:49 • by Hyuga (unregistered)
135897 in reply to 135800
Nomen est omen:

Country != preferred language; browser's idea of preferred language != preferred language. Those little flags at the top of web sites are really a nice way of handling i18n. A lot of web frameworks get this wrong.


Strongly agreeing here. Another annoying thing: In the Windows region settings, there's an option for what encoding to assume when a non-UTF-8 encoding is encountered. I have this set as Japanese (which I assume is Shift-JIS, but they just say "Japanese") because I use a lot of Japanese software, and not all of it is UTF-8. But I have my locale set as English (United States). But lots of programs use that former code page setting to determine what language I want. For example, when I download the installer for Nero, I'm not given any language options. It seems to just have every language built into the installer. But there is no way to choose. It just picks Japanese automatically and installs everything with Japanese. Sure I can read it, but I'm not the only one using that computer. I want it in English. But the only way to get the English language files is to either rip them out of the installer executable, or download them separately.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 15:10 • by verisimilidude (unregistered)
135903 in reply to 135892
Anonymous coward:
rjn:
Actually, I think it's Java...
Did Java gain the foreach keyword recently?


Java just overloaded for. If the code says

for (int i : myIntList) { ...}

it is exactly the same as c#'s

foreach (int i in myIntList) { ...}

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 16:30 • by Olius
135928 in reply to 135791
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.


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

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 17:17 • by Pat (unregistered)
The real WTF is that his XML comments are incorrectly formatted (param comment will get ignored)

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 19:03 • by redds
135955 in reply to 135873
Flash:
Yeah, but if 100000 people were pissing in the river at the same time, it would start to become an issue.


a web server recieving 100000 CONCURRENT connections at EXACTLY the same time? Be serious... you will be bottle-necked by other resource limits long before you overload the CPU or RAM with this simple string check. If nothing else, you'll have hit the network bandwidth limits and it wont matter if it takes a couple extra cycles to compare your strings.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 19:18 • by redds
135956 in reply to 135872
snqow:
The way I see, globalization frameworks should work like this:

1) check user cookie. If he has set some specific language, use it
2) nothin' in the cookies? then ask the browser
3) figure by the ip? (optional)
4) all failed? well then, fall back to app's native language



I have no problem with this kind of localization conceptually, but there is at least one major argument for supporting language choice by URL instead of, or in addition to using the browser preferences.

Consider search bots... if you support content in a dozen different languages, with english as the default. Then suppose you can get to the non-english languages by having a cookie or a browser that supplies a language preference. But how then will a search spider that doesn't provide a language choice or support cookies be able to index your non-default language content?

Sure the search spider will get to the default language version of your site and index that... but that doesn't help the german speaking user trying to search for german content phrases.

By avoiding URL based language choice you also avoid getting your site indexed.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-10 19:50 • by znation (unregistered)
135961 in reply to 135892
It did, in Java 5 or 6 (can't remember which), but I'm still convinced due to the .aspx extension and the XML method comments that it's C# under ASP.NET.

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-11 04:08 • by Grovesy (unregistered)
135989 in reply to 135872
.net also allows you to load up a Satellite assembly (basically a localised resource file) dynamically..

so, often what I have done is allow the user to click on a flag / dropdown which represents their Lang-locale. From there just pass the selected language into a wrapping resource file getter class and have that select the correct resource file to read from.

myAssembly.en-gb.dll
myAssembly.en-us.dll...



And yes, this is C#

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-11 06:37 • by Kiss me, I'm Polish (unregistered)
Speaking of classics: Microsoft is inspired by the Wooden Table Format (let's call it WTF for short) to promote Dynamics in Belgium.
I knew they actually do read worsethanfailure.com!

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-11 09:30 • by Grovesy (unregistered)
136019 in reply to 136001
Many of us do....

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-11 09:30 • by Grovesy (unregistered)
136020 in reply to 136001
Many of us do....

Re: Classics Week: Laying the Foundation for i18n, Brick by Brick

2007-05-11 09:30 • by Grovesy (unregistered)
136021 in reply to 136001
Many of us do....
« PrevPage 1 | Page 2Next »

Add Comment