- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Welcome to Spain! 4 official languages and two more big dialects, 5 very different ways to pronounce the biggest Spanish language (castellano), not forgetting about Latin America... J.
Admin
Forgive me, but I thought the Swiss and Belgians spoke chocolate?!!
Admin
Admin
I think in English, we call that language 'Flemish'.
Admin
Don't mean to start a flame, but sure looks like an ASP.NET coder with heavy PHP background. ASP.NET provides easy-to-use localization features, with no need for code duplication and/or url rewriting. Then again it's not the technology/language, it's how you use it.
Admin
In fact, these codes are all standard ISO 639-2 codes for the various languages. ISO 639-2 provides a 3-letter code for almost 500 of the world's languages. (ISO 639-3 isn't quite a standard yet, but when it is, it will provide upwardly compatible 3-letter codes for all 7000+ languages.)
The reason for the "dut/nld" discrepancy is that 22 languages have two different 3-letter codes in 639-2 for backward compatibility. Unfortunately, the official list at http://www.loc.gov/standards/iso639-2/php/English_list.php doesn't explain this very well, and lists the backward-compatibility code (which it calls the "bibliographic code") first in its tables.
As for the 2-letter codes, they belong to the closely related ISO 639-1; the table above includes all of them. Every language (almost 200) with a 2-letter code also has a 3-letter code.
Admin
The language is C#, and the syntax String[index] is basically syntactic sugar for the Property String.Chars(index) (http://msdn2.microsoft.com/en-us/library/system.string.chars.aspx), which requires a METHOD CALL.
So to complete the test of all three characters requires SIX (6) method calls, not none as some people seem to be implying.
Heck, (url.IndexOf(str, 1) == 0) might be faster. The reasoning? In Java at least, the source code of String.indexOf() shows that it tests against the char[]'s that back the Strings being tested. Assuming the implementation of String.IndexOf() in the .NET Class Library is similar, it may be more efficient to let the underlying class perform the char-to-char comparisons, rather than extract each char with a method call and performing the comparison yourself.
Admin
In switzerland we got 4 official languages (http://en.wikipedia.org/wiki/Switzerland) which are: German, French, Italian and Romansch
Since english is so prevelant in the world, we are consindering to teach our childern english as the second language. So for a mere 7 milion population, we are proud of our multi-culturated-ness (sp?) ;)
Admin
Java and C# developers don't know the meaning of optimal.
Admin
in fact, in belgium we speak chocolate AND drink beer, while in swiss they speak chocolate AND eat cheese: that's two different dialects...
Admin
@Derrick Pallas: The article doesn't display properly in Firefox... although it is fine in IE.
Admin
Admin
Admin
In Germany, apart from german we have frisian, danish and at least one more separate language (which I can't remember right now) spoken by minorities. That does not account for all the dialects of german.
German is also a minority language spoken in Switzerland, France (Alsace-Lorraine) and Italy (Southern Tyrol). The Austrians speaks german, too, of course.
Other noteworthy minority languages are Basque (Spain and France), Catalan (Spain), Gaelic (both Irish and Scottish "versions") (UK), Welsh (UK).
Switzerland is a case for itself: the official languages there include German (Swiss German dialect), Italian, French and one or two more languages spoken by very small minorities (can't remember the names right now).
In Belgium they speak French in the South and Flemish (essentially Dutch - don't flame me Flemish readers) in the North.
The list is by no means complete.
Admin
Without knowing the exact requirements and circumstances, it is impossible to say that there is anything wrong with the SOD. For example, why use a three-letter language designator where no software would require more than a single character? What is the result of this function used for? Does the result end up as part of dynamic URL?
It's always difficult to derive the module requirements or the programmer's intention solely from reading the code, but the following seems to do the same thing as the SOD, and might be faster, especially if more countries were added.
I have assumed that the function must return a three-letter string representing the ISO language, and I have added the requirement that each page preparer memorize and use a single letter representing his target language. This means the URLs would be "http://www.company.tld/e/products" for English and "http://www.company.tld/g/products" for Deulish. Of course, if the returned value is used to construct further URLs, then the code would be different.
Since Substring may be slower than two two subscripted comparisons, only a performance comparison will reveal which version is optimal.
-Harrow.
Admin
Assuming the table is sorted, represent as an INT (pack the characters).
Then, use the following WTF code (C-ish, not checked):
#define CV(c0, c1, c2) (((c0) << 8) | ((c1) << 8) | (c2))
char *verify(char *s) { int v = CV(s[0], s[1], s[2]); if (v lt CV('.', '.', '.')) { if (v lt ...) { ... return "..."; ... } else { /ge/ ... } } else { /ge/ ... } }
etc. Nested binary search. Unrolled. Given that there are 11 entries in the table, worst case:
4 if statements (compare/branch) 1 return.
So, the function executes in 9 machine instructions (worst case).
As a "double plus" bonus: the full implementation would be completely ugly WTF code -- including mis-using types, horrible looking nesting. Implicit sorting. Hard to maintain (can't add a new country without rewriting the WHOLE function). 4 levels of 'if' nesting.
I would put this into a program, just for laughs.
Admin
Derrick, could you possibly make it not-broken? That would be greeeeeat, thanks. [takes sip of coffee]
I'm using FireFox 2, by the way.
Admin
Admin
I guess he didn't know about Array.Exists?
Admin
You must be from Amsterdam.
Admin
Admin
Admin
The island is called Great Britian, as it is the largest island in the British Isles. Britain is used as a short name for the United Kingdom of Great Britain and Northern Ireland, a supernational soveriegn state including the countries of England, Scotland, Wales and Northern Ireland.
Admin
Looks like someone was still thinking in C while programming C#. Anyway, even C uses short-circuit boolean operators, so there is no need to nest the "if"s. Anyway, this function has "premature optimization" written all over it.
Admin
I thought they spoke European.
Admin
Tuota... Europe on ihan varmasti ruotsalainen. Och samma på svenska.
Admin
(Also, looking at Reflector, it looks like IndexOf() does not perform a simple binary comparision in .NET... The results depend on the current culture and comparision options, and it performs several nested function calls and parameter validations to handle this correctly. The Chars property, on the other hand, calls a native function. So calling Chars twice per loop may still be faster than calling IndexOf once per loop.)
Admin
I could not agree more hahahaha
Admin
... is premature optimization. I highly doubt this operation makes any serious change in the speed of the app.
Admin
Come on, that's not that bad. I really don't understand why the function is named IsoFromUrl, though.
Admin
Yep. Big case of premature optimization.
The fact that the programmer thinks that this is a case where optimization is more important than clarity, extensibility, and maintainability shows that he doesn't really understand what's happenining in his system.
Granted, that's not so much a WTF mistake as a rookie mistake. Unless the guy was the chief architect or something.
Admin
We speak Italian in Italy (would you ever guess???), broken english on the net, and... of course ...the language of love abroad ;-)
Respectively ITA, BRE, & FCK
CAPTCHA pinball: All around the world baby....
Admin
Maybe not; compiler may inline those methods.
Admin
Well, globalised pop culture and the Internet are actually causing causing parts of the language to converge again. especially slang.
But they're mere dialects anyway. As if the entire USA has the same word for coke, soda and pop.
Admin
James I styled himself King of Great Britain, France and Ireland, when he upgraded from just being James VI of Scotland. They didn't have a good grip of version numbering back then.
Admin
The whole optimisation is stupid anyway. The function is called once per request WOW, so that is like, every minute when the user clicked another link? Yeah, that really needs ultra-optimisation, unlike that while( ) loop that displays our 10000 products.
Wouldnt the best way be to actually parse the URL String once into a URL class, with a int country and only pass that class around? ^^
Admin
Call me crazy, but I'm guessing it's because it gets the ISO code from the URL.
Admin
To be really pedantic, in Germany we speak Deutsch You may call it German, but I know the language I am speaking. It is Deutsch
;-)
Admin
[quote user="mbvlist"][quote user="joerbanno"][quote user="Guybrush"]In and in Switzerland they speak German, Italian or some other language I forgot, and so on.[/quote]
In Switzerland they speak:
German (64%) in the north and centre; French (20.4%) to the west; Italian (6.5%)
Admin
So, given everyone's comments that we speak this, that or the other thing here, there and everywhere, the language used to post comments and short-hand here in wtf-land is wtf-ish?
Admin
George Bernard Shaw said it best:
Admin
Okay, aside from the likelihood that there's no fathomable reason for this optimization, and in and of itself it doesn't work, here's another:
By returning an ISO code string they are requiring another piece of code somewhere to be doing a switch statement (aka string of equality tests) based on strings, which is highly non-optimal.
If they had an enumeration for the countries, and returned that, then the switch on the ISO code returned would be supported at the hardware level directly. Adding a simple wrapper that translates the enum value to a string would be simple enough for the handful of cases where the caller really wants the string.
So, the problems here are:
Admin
And German, just for good measure.
Admin
Thankfully none of the North American countries do that </sarcasm>
Admin
Shoddy workmanship....
Admin
I hate when site does that! I'm French Canadian (Québécois, we too have multi-language countries in America) and I hated it the first time I went to Google with my English Windows but French Canadian preferences loaded like keyboard layout and Google redirected me to a French version of the page... Took me a while to make it remember I wanted English page.
Admin
No one forgets his lock in Amsterdam, it's like forgetting to flush the toilet.
Admin
This is the greatest comparison of Europe to America in 50 words or less that I have ever read. Actually, it's brilliant. Should I reference "CodeSOD" whenver I quote this excerpt?
Admin
The JIT does in fact optimize the calls away. The call instructions still appear in the IL, but they aren't in the generated X86.
Admin
We are an interesting country: when Czechoslovakia was about to break up, they came over to see how we had our state organized, and promptly made 2 separate countries. Haha.
I speak Dutch (Flemish), btw.