- 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
Probably a PSV hooligan with 'Eindhoven' repeated that many times.
Admin
I... don't... understand...
Admin
the rwtf is a language that permit this kind of code
Admin
Hey you can make that in any language that supports the switch statement (as well as those that don't, think repeated if's with identical condition and code block) Some compilers may optimize it away in the resulting compiled code, but it will still be there in the source code....
Admin
in c# you cant
Admin
I don't know about other C++ compilers, but apple LLVM considers multiple cases with the same value an error.
Admin
Admin
I think the story about how that code evolved might be an interesting one. Perhaps it originally converted variations like "EIN", "ein", "Ein" and so on. ToUpper() (or whatever) must have been after switch in the book and so that was introduced to the code later and maybe some global replace editing function was used to set all the existing instances to "EIN" because the variations wouldn't be required any longer but it wasn't really thought through. I like to think that there has to be an explanation like that because nobody could be that stupid.
Admin
Thats no explanation for why the switch statements have different length though.
Admin
Granted, I feel dumber for having read this code block, but can anyone figure out why this code would have been written in this manner? Are we talking about 6 possible destinations from Eindhoven, and 12 possible ways to get to Wroclaw? I wonder how it passed code review....hahahahahahahaahhahahahahahahahahahahahahahaha, OK, I'm good now, I can breath again!
Usually even with steaming piles of code, you can see what the dev was trying to accomplish, even when the path taken was completely devoid of any logic or understanding of the language basics. But this one is shitty in a whole new way. Possibly generated using an excel macro or something, generating a static code insert for each pair of origin/destinations?
Oh well, I know what my nightmares will consist of tonight, many trips from Eindhoven to Wroclaw, over and over and over......
Admin
Code Review? Right! Reread the frist paragraph.
Interesting trips where you arrive twice as often as you depart. Well, better than the other way around.
Admin
I think your sarcasm filter is malfunctioning.
Admin
Did she move on to a lucrative career at British Airways?
Admin
Now that is one funny comment!
Admin
This is elegant, if you get paid by the number of lines you produce.
Admin
Winner!!!
Admin
I think the speculation above that a global search and replace changed all the variations to a single case caused this. Of course its terrible to do a global search and replace and NOT CHECK WHAT IT DID.
Admin
This is not C, it's PHP (aka The Universal WTF). C/C++ only lets you switch on integer types and does not allow duplicates.
What bothers me about this code is what it does when the default case happens and the string is not changed from... what?
Admin
Could the culprit be trying to support if someone wrote 0 instead of O? And then did the same search-replace.
Admin
Gladly this will be killed by the compiler for sure!
Admin
I would be more concerned as to why each switch is for a different variable!
Admin
I've left a few websites in my wake which looking back make me cringe because of how far I have come since then. Many of them are still up which also makes me feel terrible.
Admin
Java supports the switch statement but will not compile that - duplicate cases are not allowed.
Admin
I'd guess that the developer was expecting to have multiple airport codes in each switch and started editing by duplicating the same clauses over and over, expecting to go back and 'fix' entries as new codes came along - then went off to something else, never to return.
Admin
Ho- Wh... huh, wait, whaaaat?
My only explanation is that she was trying to do something, but then was diverted to something else and forgot about that for the rest of her life.
Admin
Actually, that's probably the most reasonable explanation. This is something that I do occasionally if I need multiple similar lines with one or two operands changed. The important part is actually following through, though -- but who knows what was going on at that office to distract her.
Admin
Most likely that same whatever caused her to leave for better job...
Admin
She moved on to United, where she continues "re-accomodating" code into unrecognizable bloody mess...
Admin
That one is easy: the first switch is the departure city while the second switch is the arrival city. Remember it say linear coding, no function, so you have to build the switch twice to test both departure and arrival...
Admin
"Attention all passengers. We have just touched down at Wroclaw International Airport. However, we have just learned that there are no vacant gates, and a flight from Japan needs to use our runway. So we are going to have to take off again in order to get out of everybody's way, and circle around for a bit till there's room for us. Damn, this happens every flipping flight from Eindhoven. Please remain in your seats and,. cabin crew, please make ready for takeoff."
Admin
I remember a WTF from days of yore that went something like this:
Manager: "Why is it taking so long to produce this document?"
Worker: "The spec changed so that wherever it refers to option "A" we have to change it to "B"."
Manager: "So why is it taking so long?"
Worker: "I have to carefully hunt through the document to find where it refers to "A" in this context and change it to "B"."
Manager: "Haven't you heard of search and replace? Oh give it here."
(Elbows worker out of the way, does a global Search and Replace for all instances of A and replaces them with B, ignore case. Presses Save then Send.)
Admin
Possibly she was diverted by something inside her brain that went: "Hang on, this approach is silly. Oh hang on, I have a far better idea." Ran off to implement her better idea, forgot to go back and flush the metaphorical toilet.
Admin
I know this isn't C. If you look a bit more closely you'll see I replied to someone claiming you can make that in any language that supports switch statements.
Admin
Why are the variable names into the switches different? No really shouldn't it just be a variable with the airport code? Does each airport have it's own variable?
Admin
Destination and origin?
Admin
I use that approach myself, but I tend to edit out changing bits, and I do not leave it for production. My code would look more like:
Admin
I think this is code is halfway through a copy-a-lot&edit('implement')-afterwards kind of style. The story does not mention whether this code was actually ever called...
You would prepare a couple of situations by copying them the number of times you need it and then change all the options according to the actual values checked against. Only, in this case, Ms GoodWithComputers saved the file in that state, was distracted or interrupted and forgot/never came round to actually changing any of the options.
Apparently, the code 'worked' (if called at all) well enough to not need any more attention...
Admin
$airport = [ "ein" => "Eindhoven", .... ] ; $dest = isset($airport[$ref]) ? $airport[$ref] : "Unknown airport" ;
Or similar comes to mind..
Admin
Attempt #1:
switch ($v) { case "ROS": $ori = "Rosetta"; break; default: break; }
Admin
Close enough, I guess.
Admin
I agree with you here. Definitely auto-generated code. Maybe she got the codes and names from a spreadsheet or database query then didn't notice the codes and names were non-distinct (maybe the first page of rows was distinct). Copy paste the result set. Run transformation macro/find-replace on it without really understanding switch statements. Code works. No need to review it.
Admin
Please create a way to report these dumb SEO spam comments or otherwise prevent or remove them... This is a website to talk about coding... and this simple thing, nowhere to be seen. lol