• (nodebb)

    A story with a happy ending. That's almost a frist.

  • LCrawford (unregistered)

    Happy ending indeed - I'm surprised that he was able to convince management of the stupidity of the code and that they didn't think it was an elegant, scholarly work having just 2 typos.

  • Peter Tramo (unregistered)

    Okay, admitting this story is not just made up, say what you want about not attributing to malice what is caused by incompetence, this is going way beyond the boundaries of carelessness and stupidity. It's not "just not caring" anymore, it's evil-inspired obfuscation. The immediate function call is mostly harmless for readability, though a clear sign of complicating things on purpose. On the other hand, only Satan himself could come with the idea of that "switch false" to hide a negation.

  • dpm (unregistered)

    I, also, cannot help but admire the "switch false". However, let us not deny the recognition due for returning an undefined value when the parameter is neither "true" nor "false". I'm even willing to award a few minor points for theoretically forcing the interpreter to execute toLowerCase() twice.

  • (nodebb)

    Code snippets like this are not made up, because there's no way to make this up, unless you're in Kerblekistan and need to increase your LoC counts. Real life always beats comedy.

  • (nodebb)

    In a real programming language, you'd get a warning_transformed_into_an_error_by_-Werror(1) about there being a path through the function that doesn't return a value.

    (1) If you aren't using -Werror or your compiler's equivalent, you are a state of sin.

  • NoLand (unregistered) in reply to Steve_The_Cynic

    Actually, JS always returns a value (ECMA script that is, not the original JS by Netscape), defaulting to the undefined primitive.

  • (nodebb)

    Gotta love that Enterprisey logic: "We switch on the value false, which forces all of our cases to do !==, only to return the opposite value."

    We do this because we offshore development to countries where toilets flush the opposite way and booleans are strings.

  • (nodebb)

    Forgive me, but I don't get it. Why was the immediately invoked function expression a problem? Other than being unnecessary?

  • Works as coded (unregistered) in reply to jkshapiro

    It's just completely unnecessary and adds nothing to the solution. It further illustrates that the developer had no idea what they were doing.

  • (nodebb)

    Oh, the fun you get when you parseBoolean("FILE_NOT_FOUND");

  • Gumpy_Gus (unregistered)

    I got an offshore one-- A company I used to work for years ago was making medical devices and they offshored all the testing. I overheard the guy in the next cubicle: "WHAT THE HE**!!!". Turns out he had just had a 3-hour conference call with the test team. First gotcha-- that it took three hours to tell them to run the last test over again. Next gotcha-- white the test was and had always been a serial contiguous 72-hour test, he got the test results, "passed with 0 errors", in under 8 hours. Last gotcha: management did not switch testers.

  • kansel (unregistered) in reply to jkshapiro

    I don't think anything's inherently wrong with the IIFE, it's just confusing and unnecessary. The entirety of the parseBoolean function could be rewritten as: return string.toLowerCase === "true"; This would also get rid of the undefined values for anything other than /true|false/i.

  • kansel (unregistered) in reply to kansel

    Gah! typo in my own code. return string.toLowerCase() === "true"; (I always forget the parens)

  • Perri Nelson (unregistered) in reply to nerd4sale

    "Of course, that didn’t mean the contract was cancelled. Other teams were now expected to fully leverage that excess capacity."

    I'm not sure how passing misery onto other teams in the company is a "happy ending."

  • (nodebb) in reply to jkshapiro

    Slower, hard to read? I hate when these are used in other contexts too

  • (nodebb)

    Except if you look at the compiled code in (second switch example)[https://coffeescript.org/#switch] on the CoffeeScript language reference page, this is exactly the same format they use.

    var grade, score;
    
    score = 76;
    
    grade = (function() {
      switch (false) {
        case !(score < 60):
          return 'F';
        case !(score < 70):
          return 'D';
        case !(score < 80):
          return 'C';
        case !(score < 90):
          return 'B';
        default:
          return 'A';
      }
    })();
    
    // grade == 'C'
    
  • (nodebb) in reply to Peter Tramo

    Maybe.

    I've seen so much incompetence that I don't believe the authors of the code are capable of competently and purposely obfuscating code in an evil manner.

    Now maybe, they think they get paid by line of code, or indirectly, if they show some bulk of work they are fulfilling their 40 hours per week - that I could believe because I have seen a LOT of code that fits that pattern.

    That said, I am not sure what the motivation is, but I lean towards incompetence.

  • I dunno LOL ¯\(°_o)/¯ (unregistered)

    Wait, what? false without quotes is a constant, right?... and switch case fall-through and... string.ToLowerCase() of what? Is this code supposed to summon an elder god or three? Because it certainly is attacking my sanity right now. Expressions in switch cases are clearly not a good thing. Duff's Device is a warm fuzzy plush toy in comparison to this creeping horror.

  • Anonymous (unregistered)

    "The regular employees ended up doing more work on the project than they would have if it had been developed in-house"

    Story of my entire life.

  • sizer99 (google)

    People attributing this to evil or enterpriseyness... no, this is just what you get when the entirety of someone's job is looking up code snippets on StackExchange, and mushing them together without any understanding till they no longer throw compile errors.

    For instance, a big part of the code comes from https://coderwall.com/p/fpbkeg/parse-a-boolean-from-a-string-in-javascript - which references a StackExchange answer that he doesn't reference and I can't find. More WTFs here.

  • Guest (unregistered) in reply to sizer99

    No, that's what happens when you use a transpiler. The coffeescript source is fairly reasonable.

  • staticsan (unregistered)

    Long before StackOverflow was a twinkle in Jeff's eye, I worked for a tiny company that tried to do some out-sourced programming. They were cut-and-paste programmers or the worst sort. One file had the same 150+ line logic copied four times with just one or two minor changes for each section. Since my boss at the time was one of the company owners, when I showed that to him, followed by what it should be, he had some strong words with the out-sourcing company. When they did not understand the problem, he terminated the contract.

  • dazworker (unregistered)

    Great find, that really makes things clearer. A bit. For those who didn't click the link: this is apparently the compiled Javascript output of a Coffeescript source. Which makes sense looking at the insanity of that switch statement.

    This does however lead to a bunch of other questions... why did the person from this post use this instead of one of a million perfectly adequate solutions that are certain to be found on Stackoverflow(*)? Why was the original creator unsatisfied with those same solutions? What lead him to not only post his Coffeescript (**), but also the Javascript, proudly declaring this a "sweet function"?

    (*) SO gets a lot of stick here, but it delivers perfectly fine solutions to questions like this (**) I don't know Coffeescript, but the code is pretty obviously an overcomplicated mess as well

  • dazworker (unregistered) in reply to sizer99

    Previous post was meant as reply to sizer99

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

    The one thing you're missing is that "string" is the name of the parameter (evil enough in itself). So the parameter.toLowerCase() will evaluate to "true" or "false" (assuming sensible input). These strings get evaluated as boolean true / false values, because evil (although that evil belongs to the language). This is compared to false, or something because the switch(false) inverts the logic. It then fails to work, I think, because the two cases have the same case. Is that right? I don't think any programmer with a shred of decency should ever have to work out what code like this is doing. Just delete, set aflame, and replace with real code.

  • Peter Tramo (unregistered) in reply to sizer99

    Nice find ! So you're right, what we have here is an incompetent coder blindly copying the result of compiled CoffeeScript as if it was proper style JS. Well guessed ! Additional WTFs : CoffeeScript compiler : why generate this double negation? Maybe it's a way to avoid some gotchas of JS comparison? Source coffeescript : why not a "else undefined" in the switch instead of this ugly typeof ? (warning avoidance maybe? I've never used coffeescript)

  • Chris (unregistered)

    Or they could have done what our team did. I was a long term contractor working for a rather large utility provider in New England. We were in the process of upgrading their customer support system when upper management mandated that we use an off-shore company. We were told to provide enough work for two full time resources. There was plenty of work to go around so that wasn't a problem until we saw the work that was being checked into source control and realized that everything that was submitted was going to have to be rewritten. Someone on the team got the amazing idea to modify the specifications and add a new form, this form was basically a duplicate of an already existing form that was already completed. To prevent the incessant compile errors, the rest of the team modified our profile to not include this form so we had no problems with compiling. Interestingly, when the upgraded system was ready for release the off-shore team was still working on their one form so we simply declared that all the work was done.

    Our PM kept track of all the time wasted and showed the reports to the chain of bosses above him. The off-shore mandate was quietly dropped.

  • foo (unregistered)

    OMG. This is javascript returning a closure. I've never seen one in the wild. Another checkmark on my life list.

  • David Mårtensson (unregistered) in reply to kansel

    No, as stated above, the implementation explicitly returns undefined if the passed value is not any of the words true or false, so your solution does not preserve the tri-state boolean of the original :P

  • Solomon Ucko (google)

    AFAIK, the reason CoffeeScript does that is for efficiency and consistency:

    • The switch is an expression, so that explains the IIFE.
    • The conditions aren't necessarily booleans, and I guess
      false === !x
      is slightly faster than
      true === !!x
      .
  • radarbob (unregistered) in reply to Bananafish

    they have toilets? Not the impression i got from the TED talk

Leave a comment on “Switching to Offshore”

Log In or post as a guest

Replying to comment #503832:

« Return to Article