• Ron Fox (google)

    My frist thought (the comparison error aside) is that the coder just knew that decision would be reversed and coded in anticipation of it.

  • TheCPUWizard (unregistered)

    Thus ends today's lesson about why strongly typed languages with validating compilers are so valuable.

  • (nodebb)

    Yeah, yeah, Ulysses removed the conditional, but kept which branch?

  • Quite (unregistered)

    Well, that was obviously tested really carefully now, wasn't it?

  • Easily Fixed... (unregistered)

    candidateNum=4 if candidateNum == "4": handleCandidate3() return true else: handleCandidate4() return true

  • SolePurposeOfVisit (unregistered)

    Four not found?

  • kktkkr (unregistered)

    candidateNum=4; return [handleCandidate3,handleCandidate4]sum([candidateNum==candidateLogic for candidateLogic in ["4",'4',[4],(4),{4},4]]) or True

    There, now it's improved(!) and only takes one line :)

  • Paul Neumann (unregistered)

    JavaScript has no type system to speak and happily coerces types silently

    Happily coercing the types which do not exist silently, eh?

  • Anonymous') OR 1=1; DROP TABLE wtf; -- (unregistered) in reply to kktkkr

    (4) is equivalent to 4. You really wanted to use the 1-tuple (4,) instead.

  • Carl Witthoft (google)

    something something there is no four, thou shalt go directly from 3 to 5.

  • Jeremy Lindgren (vita10gy) (google)

    This mistake is understandable (well, outside of "why not just remove the conditions", though we've all been there and the answer is probably "for when the client changes their mind back in a week)....but I'll never understand how this gets passed testing. How vital can this change have been if no one noticed that instead of always doing 4 it never did 4?

  • NotBugItsFeature (unregistered) in reply to Jeremy Lindgren (vita10gy)

    Testing? What's that?

  • (nodebb)

    Perhaps it was working as intended, where handleCandidate4() is the one that should never be called, and handleCandidate3() should always be used; but the developer thought it would be funny (or something) to make the code confusing.

  • Zylon (unregistered)

    "JavaScript has no type system"

    Well, that explains the "typeof" and "===" operators.

  • (nodebb) in reply to Ron Fox

    Been there. Done that. And they did ask for it to be changed back the next month.

  • Anonymous Coward (unregistered) in reply to slapout1

    I like to handle these by putting a bit mask in the config file:

    <add key="InstanityLevel" value="10" />

    Then you can compare later in your code:

    if (InsanityLevel & 2) { // do something insane } else { // do something sane }

  • TimothyB (unregistered) in reply to Zylon

    For reference: http://scholar.harvard.edu/files/mickens/files/towashitallaway.pdf In particular the section that begins:

    For example, it would definitely be horrible if your browser’s scripting lan- guage combined the prototype-based inheritance of Self, a quasi-functional aspect borrowed from LISP, a structured syntax adapted from C, and an aggressively asynchronous I/O model that requires elaborate callback chains that span multiple generations of hard-working Americans. OH NO I’VE JUST DESCRIBED JAVASCRIPT. What an unpleasant turn of events! People were begging for a combination of Self, LISP, and C in the same way that the denizens of Middle Earth were begging Saruman to breed Orcs and men to make Uruk-hai.

  • kktkkr (unregistered) in reply to Anonymous') OR 1=1; DROP TABLE wtf; --

    (That was the joke, and it's kind of an improvement because it doesn't fail silently by taking the wrong branch. Of course, the error would be harder to fix once discovered.)

  • Bill C. (unregistered)

    No matter which candidate they asked to handle, they get trumped.

  • Bill C. (unregistered)

    Oops, did I just say that? Oh no. I survived everything else up to here, and now Hillary's going to kill me.

  • Comelec Chairman Andres Bautista (unregistered)

    Hey, what hacker leaked our STATE SECRETS onto the Internet? I'm going to sue you guys.

  • v (unregistered)

    I like how the author admits he is terrible at JS, and probably at programming in general as well.

  • (nodebb)

    By this time handleCandidate4 and handleCandidate3 probably do the same thing anyway.

  • Anonymous (unregistered) in reply to urkerab

    By this time handleCandidate4 and handleCandidate3 probably do the same thing anyway.

    TRWTF is that they were ever supposed to be different.

  • Axel (unregistered) in reply to TimothyB

    Am I the only one who read

    towashitallaway.pdf

    as

    tow a shit all away

    ?

Leave a comment on “The Difficulties of Choice”

Log In or post as a guest

Replying to comment #:

« Return to Article