- 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
You hate it when your web browser delivers the web page you told it to deliver?
Well, at least now you've learned the complex task of configuring your system to deliver the actual language you want, right?
Sheesh. What next? "I went to Flickr and my web browser downloaded a load of images! Waah!"?
Admin
I guess you don't recognize a joke when you see one.
Admin
No no no, that is bad practice. Then the visitors can't choose in which language they want to see the site. You shouldn't make them have to fiddle around with the browser settings for every site on the internet.
Admin
Actually, if you assume that the URL includes a valid 3-character code, why not just:
(Or whatever this language uses to concatenate 3 characters. Or maybe a MID() function?)
The only difference here is that the original code will return
if the three characters don't match anything in the table.Admin
Is there something I'm missing here? It looks to me like the method takes a string, and in 99.999% of likely scenarios, returns the characters 1-3 of the same string. Unless the cost of returning a string that isn't a recognized locale is astronomical, you should just convert this to
public static string IsoFromUrl (string url) { return url.SubString(1,3); }
Admin
I have a Hummer bicycle. It weighs 300 lbs, 48 gears, GPS, sound system, can carry 4 people, can crush a small car. A great bicycle but it's a real bastard up the hills.
Admin
It's worse with the msdn. It takes the config from the operating system and does not let you change the default. All I want is to see the help in english, I don't want to get used to read technical documentation in spannish.
BTW, a more complete map of european languages is here: http://www.eurominority.org/version/maps/map-european-languages-eu.asp
Admin
Dutch, French and German are the official languages in Belgium. Arabic is the second most spoken language in Brussels after French.
Admin
My condolences.
Interesting fun fact: As a Dane, reading a Dutch newspaper is quite possible (easily 75% comprehension) but listening to Dutch ... 0% comprehension.
Admin
Admin
This is C# because it is the only language that uses string(with no capital letter), and also the style of comments used is unique only to C#.
That code won't even work because, it only tests for the first 3 letters, for example, what happens if the user enters this url http://www.company.tld/engthisisawtf/products.
Admin
I profiled a few ways of doing this in Ruby (yes, it's slow, but results in a happier programmer than C#). Tested with N=1000000, 20% miss rate (unless specified in the test). Results in seconds.
So the Hash key test is the fastest, by far (at least in Ruby). So WTF is up with these guys? Note that this assumes that the random test URLs are evenly distributed across the languages, which may not be the case.
Admin
An enum would have worked better, or use the built in globalization capabilities of .Net.
captcha: dubya. sigh please don't remind me.
Admin
Orion, is that you? Dude, give me a shout!
Admin
public static string IsoFromUrl (string url) { switch(url[1]) { case 'd': switch(url[2]) { case 'a':return "dan"; case 'e':return "deu"; case 'u':return "dut"; default:return String.Empty; } case 'e': return "eng"; case 'f': switch(url[2]) { case 'i':return "fin"; case 'r':return "fra"; default:return String.Empty; } case 'j': return "jpn"; case 'k': return "kor"; case 'n': return "nor"; case 's': switch(url[2]) { case 'p':return "spa"; case 'w':return "swe"; default:return String.Empty; } default:return String.Empty; } }
Admin
Admin
Ignore this post ^^^ what I thought was a bug was actually sound logic...
Admin
I tested this code. I also tested several variations (rolling the loop back up, using an index instead of an iterator, compacting the strings into integers, etc.). NONE performed any faster than the posted code (well... sometimes using 'for' instead of 'foreach' was marginally faster). Some form of esoteric search algorithm might be faster, but for just a few lines of code, the posted solution is fantasic.
This is most definitely NOT a WTF.
Admin
:-/ If you also assume that the URL coming in has already been trimmed you can just do a "return url;"
I actually like this because they put a comment as to why they did what they did in the code. I hardly ever see that in practice. Although it would have been better within the code block rather than outside it.
Admin
Meta solution? ;-)
Admin
He told it to go to google.com, instead it went to google.fr (I assume, notice how he said it did a redirect) So no, he hates it when it delivers a page he didn't tell it to deliver.
Admin
you missed the point, it most definitely is. not because the code is or is not optimal performance-wise, but because:
it is more than suboptimal regarding extensibility and maintainance
in any decent web-framework there is extensive support for i18n, without having to roll your own half-baked solution (mind, it is not even shown how the extracted iso language string is used inside the pages - the next WTF might be just lurking there. I strongly fear something like a switch-statement for every localized string inside of HTML-embedded code snippets or some similarily nightmarish thing...) if the framework of choice does not support i18n, throw away the framework and use a better one instead of re-inventing the (most probably not quite so round...) wheel. that's what frameworks and standardized platforms where invented for.
captcha: onomatopoeia - finally I got that famous one ;o)
Admin
Well, google choses the language not according to the settings of your browser, but to the country you're in. So my browser does say that I want english, and french if that's not available, but until I go to google's preferences, and save a magic cookie, it comes in japanese. I hate that when web sites assumes that countries = languages, and that everybody in a country is a local. At least, with japanese I can handle it. But it was certainly a nuisance last time when I was in thailand. And of course, it is very famous that nobody ever ever goes on holidays in thailand. They probably just build the biggest airport in asia just to show off.
Admin
the best fix to this is:
if speed is needed, there's two methods that can be used, with a hash table or with binary search. The binary search would be as follows
Admin
What this is is a 'trie'.
I once benchmarked tries versus hashes versus linear search for tiny dictionaries (less than 20 name-value pairs). Despite expecting a linear search to be fastest on such small datasets the trie came out tops by a long shot. That was with the each string compare dropping out as soon as it found one character wrong (normally the first). However, the linear search was almost certainly fast-enough.
A bunch of IFs is often faster than a case statement too, especially as small case statements often end up as if statements anyway. Take a look at re2c to see this working in practice.
Most modern CGI's do so much in each request anyway that this type of optimisation is generally redundant. I'm sure this CGI in question went on to make call after call to an SQL database..
Admin
That's the fastest almost certainly..
Admin
[quote user="nooblar"][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%) [/quote]
and: (source: eurominority.org)
That should it as regards to Switzerland.
Addendum (2007-02-08 11:47): That should be it as regards to Switzerland.
Sigh - sorry.
Admin
So what is the big deal with that: are you thinking that in the US only english is spoken ?
FYI: Languages spoken in the US I can think of right away:
If I did forget anything, no offense intended - this is just a shot from the hip.
Admin
You should reference "Sir Derrick Lyndon Pallas" and (if possible) link to http://derrick.pallas.us
Admin
And Chinese in Cupertino...
Admin
Admin
Yeah, if only
Admin
Surely there's a C# equivelant for this PHP code:
This checks for the language in the array. If it doesn't exist, it defaults to English :)
Admin
"deu" is the three letter iso language code (ISO 639-3) of german. "de" is the two letter code.
In the ISO country code "DEU" stands for German and "CHE" for Switzerland. But we are more used to the IOC country codes which are used for sports activities. There it's "GER" and "SUI" for instance.
Admin
Please don't try to pin on the finnish something we are not responsible for.
Admin
English is a european language.
Try expressing yourself again in native american.
Admin
Actually the Island is called Britain. England is one of the three countries on that Island.
Admin
The biggest WTF here is that people say they can write faster code, but don't actually instrument it!
I tested two of the supposedly "faster" proposals made here, and they are both slower.
In the code below, Test0() is the original code, Test1() is the code that uses Array.BinarySearch(), and Test2() is the code that uses a single prefix character to speed lookup.
On my system (Pentium 4, 2.8GB) the results are:
Test0() took 102ms, Test1() took 1112ms, Test2() took 162 ms.
Most amusingly, the Array.BinarySearch() proposals is over 10 TIMES slower that the original code. :)
The moral of this? INSTRUMENT YOUR CODE BEFORE MAKING WILD CLAIMS ABOUT IT'S SPEED!
Here's the code. Sorry about the bad layout.
Admin
You're all missing the point: Because of the greater disparity of end letters as compared to starting letters ( 2 'f' and 3 'd' ), to optimise this code you should surely reverse the order of testing, so as to minimise the number of 'if' clauses performed, thus: ( I can't get the formatting to work, apologies )
foreach (string str in VALID_FOLDERS) { if (str[2] == url[2]) { if (str[1] == url[1]) { if (str[0] == url[0]) { return str; } } } } There. That's better...
Admin
As for the condolences, I'm sure he'll be fine.
As for Danes understanding Dutch, I can assure you that this is also true the other way round. Danish is about as inconsistent in its pronunciation as English is.
About the original post: the expression "as optimal as possible" is butt ugly, if not simply wrong.
Admin
An even bigger wtf is you cleary underestimate the netherlands and europe in common, which, for one, found your 'great' America (New York used to be New Amsterdam).
Our small cars have a lot more comfort and luxurious on the inside then American cars, even in cheaper cars ;). And about speaking alien when there are no forgeiners around.. so true ;)!
Admin
I've just read through all the comments, and I don't see anyone pointing out that, since the url is of the form "/lang/foo/bar.aspx", the three characters being compared from the url (url[1], url[2] and url[3]) are not the country code at all, but are always "lan".
Therefore it will always return an empty string, IF it's called as per the description. In any case, it's a WTF.
Admin
My guess is that Jannik works at a German company? ;) (<generalisation>chauvinistic bunch</generalisation>)
Admin
Why is it
instead of ?Admin
I where they said "lang" in that URL, they meant the 3 character language code. They should have put <lang> in the URL, and then said "where <lang> is a 3 letter language code blah blah".
Admin
Try reading the post for a change.
Admin
Oh, man,I nearly had an aneurism from laughing at that. That's probably what their elementary school maps look like...
Admin
The island is called England? My, those Scottish and Welsh people would love to hear you call it that...
Admin
Flemish.
Admin
Said the Dutch prostitute with a nasty chest cough to the customer wanting to loosen up while waiting for her to finish with the Frenchman.