• A_L (unregistered)

    Probably a PSV hooligan with 'Eindhoven' repeated that many times.

  • Jordi_Olot (unregistered)

    I... don't... understand...

  • giammin (unregistered)

    the rwtf is a language that permit this kind of code

  • Yazeran (unregistered) in reply to giammin

    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....

  • giammin (unregistered) in reply to Yazeran

    in c# you cant

  • Greg (unregistered) in reply to Yazeran

    I don't know about other C++ compilers, but apple LLVM considers multiple cases with the same value an error.

  • Ulysses (unregistered)
    switch($phb)
    {
        case Ballmer: chant = "Developers";
        case Ballmer: chant = "Developers";
        case Ballmer: chant = "Developers";
        case Ballmer: chant = "Developers";
        case Ballmer: chant = "Developers";
        case Ballmer: chant = "Developers";
        case Ballmer: chant = "Developers";
        case Ballmer: chant = "Developers";
    
  • anon (unregistered)

    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.

  • dot (unregistered) in reply to anon

    Thats no explanation for why the switch statements have different length though.

  • timmy (unregistered)

    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......

  • Foo AKA Fooo (unregistered) in reply to timmy

    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.

  • timmy (unregistered) in reply to Foo AKA Fooo

    I think your sarcasm filter is malfunctioning.

  • EinHaven (unregistered)

    Did she move on to a lucrative career at British Airways?

  • timmy (unregistered) in reply to EinHaven

    Now that is one funny comment!

  • Che (unregistered)

    This is elegant, if you get paid by the number of lines you produce.

  • Guess-the-guest (unregistered) in reply to EinHaven

    Winner!!!

  • my name is missing (unregistered)

    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.

  • I dunno LOL ¯\(°_o)/¯ (unregistered) in reply to Greg

    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?

  • Guest 54632 (unregistered) in reply to dot

    Could the culprit be trying to support if someone wrote 0 instead of O? And then did the same search-replace.

  • OTee (unregistered)

    Gladly this will be killed by the compiler for sure!

  • OldCoder (unregistered) in reply to dot

    I would be more concerned as to why each switch is for a different variable!

  • <(''<) <( ' ' )> (> '')> (unregistered)

    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.

  • Developer Dude (google) in reply to Yazeran

    Java supports the switch statement but will not compile that - duplicate cases are not allowed.

  • Steve (unregistered)

    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.

  • MaxArt (unregistered)

    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.

  • CrazyEyes (unregistered) in reply to Steve

    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.

  • Klimax (unregistered) in reply to CrazyEyes

    Most likely that same whatever caused her to leave for better job...

  • Michal Rysanek (google) in reply to EinHaven

    She moved on to United, where she continues "re-accomodating" code into unrecognizable bloody mess...

  • Olivier (unregistered) in reply to OldCoder

    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...

  • Quite (unregistered) in reply to Foo AKA Fooo

    "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."

  • Quite (unregistered) in reply to my name is missing

    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.)

  • Quite (unregistered) in reply to MaxArt

    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.

  • Greg (unregistered) in reply to I dunno LOL ¯\(°_o)/¯

    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.

  • This boggles me (unregistered)

    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?

  • Duh (unregistered) in reply to OldCoder

    Destination and origin?

  • Gene Wirchenko (unregistered) in reply to Steve

    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:

    switch ($v) {
            case "EIN": $ori = "Eindhoven";
                break;
            case "YVR": $ori = "Vancouver";
                break;
            case "FUK": $ori = "Fukuoka";    // gave me a start the first time I saw this one
                break;
            case "": $ori = "";
                break;
            case "": $ori = "";
                break;
            case "": $ori = "";
                break;
            default: break;
        }
    
  • J!P (unregistered)

    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...

  • Ghost (unregistered)

    $airport = [ "ein" => "Eindhoven", .... ] ; $dest = isset($airport[$ref]) ? $airport[$ref] : "Unknown airport" ;

    Or similar comes to mind..

  • Anonymous (unregistered)

    Attempt #1: switch ($v) { case "ROS": $ori = "Rosetta"; break; default: break; }

    switch ($b) {
        case "67P": $des = "67P/Churyumov–Gerasimenko";
            break;
        case "67P": $des = "67P/Churyumov–Gerasimenko";
            break;
        case "67P": $des = "67P/Churyumov–Gerasimenko";
            break;
        default: break;
    }
    
  • Anonymous (unregistered)

    Close enough, I guess.

  • RG (unregistered) in reply to timmy

    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.

  • Omid (unregistered)

    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

Leave a comment on “Switched Over”

Log In or post as a guest

Replying to comment #:

« Return to Article