• Wonk (unregistered) in reply to queso
    queso:
    There actually is a 5.

    And that's connection code.

    TRWTF is no case 5: break;

    That's because there are only 4 lights.

  • Terry (unregistered)

    He's making a list, and checking it twice...

    Didn't your mother tell you, if it is important, you should always double check?

    He's just trying to write fault-tolerant code for an embedded system. Not a WTF. And he's paid by the line. And it's just in dev anyway, as others mentioned.

    Maybe TDWTF is the victim of its own success. We've shamed all the crappy programmers out of the profession. Stupid mistakes aren't being made any more. And I have this great app for managing the Brooklyn Bridge to sell you.

    But I, too, have submitted worthy (IMHO) WTFs and had them ignored. So, it's off to the sidebar, or maybe failblog or something...

  • (cs)

    TRWTF is breaking in both the if and else instead of at the end of the case... :-X

    But no, break does not break out of if blocks in JavaScript, ... Fucking trolls.

  • AP² (unregistered) in reply to McKay
    McKay:
    AJAX is asynchronous and multi-threaded.

    Wrong. It is asynchronous, but no browser runs Javascript from the same page in more than one thread.

    McKay:
    Yes, this code is a little silly, but I imagine the developer had the status change on him twice in quick succession, and the event fired twice, and figured this was an appropriate fix.
    That doesn't make sense, because the first three checks are irrelevant, and the fourth can't change - if the response has finished receiving, what would it change to?

    This is just poor code.

  • (cs) in reply to trwtf
    trwtf:
    Nagesh:
    trwtf:
    Nagesh:
    I am first. Am I not? Akismet, whatever you are. Damn Yuo.
    Indian coders are always first but you have to ask yourself - do you want it done fast or do you want it done right??? I'm guessing your code is about as useful as your comment.

    As for today's WTF, I've seen people make superfluous checks plenty of times before but I can't recall ever seeing code that checks the same variable twice on the same line. That's... interesting.

    That's cos of timeszone dear.

    English isn't your strong suit, is it?

    After being ruled by English for several decades, I decided to get back at them by slaughtering their language. Call me Daniel Webster of Hyderabad.

  • (cs) in reply to Nagesh Kukunoor
    Nagesh Kukunoor:
    trwtf:
    empathic:
    And not being Hitler isn't yours, is it? Stop being racist, dude, calm down.
    You're the one who brought Hitler into the conversation. Isn't there some rule about how it's the dumbest people with the weakest arguments who are the first to raise comparisons to Hitler?
    +1 for identifying a case of "Reductio ad Hitlerum" (and no, it's not Godwin's Law, that's something different). I agree, as soon as you invoke Hitler your argument is completely invalid and your opinion is about as useful as an offshore coding team.

    Please stop using my name.

  • (cs) in reply to akatherder
    akatherder:
    It depends on the data shown in the alert() box is. It could be "Your request number 12345 has been logged" and that message may have just been written to tblRequestLog. It's sloppy, but there's nothing wrong with alerting an AJAX response in production.

    Here are the other readyStates: 0 - The object has been created, but not initialized (the open method has not been called). 1 - A request has been opened, but the send method has not been called. 2 - The send method has been called. No data is available yet. 3 - Some data has been received; however, neither responseText nor responseBody is available. 4 - All the data has been received.

    I've never had any use for any of them but 4. I can't think of a process where the others would be actionable.

    You have never seen a progress meter or wait graphic displayed during an AJAX call? As soon as it hits state 1 you want to disable whatever control caused the call to reduce redundant requests.

  • Jay (unregistered) in reply to Nagesh
    Nagesh:
    trwtf:
    Nagesh:
    trwtf:
    Nagesh:
    I am first. Am I not? Akismet, whatever you are. Damn Yuo.
    Indian coders are always first but you have to ask yourself - do you want it done fast or do you want it done right??? I'm guessing your code is about as useful as your comment.

    As for today's WTF, I've seen people make superfluous checks plenty of times before but I can't recall ever seeing code that checks the same variable twice on the same line. That's... interesting.

    That's cos of timeszone dear.

    English isn't your strong suit, is it?

    After being ruled by English for several decades, I decided to get back at them by slaughtering their language. Call me Daniel Webster of Hyderabad.

    Oh well. Your English is probably better than my Urdu anyway.

  • Brendan (unregistered) in reply to xtremezone
    xtremezone:
    TRWTF is breaking in both the if and else instead of at the end of the case... :-X

    But no, break does not break out of if blocks in JavaScript, ... Fucking trolls.

    That's why it's always better to use GOTO instead of break, continue, etc; especially in JavaScript..

  • Bob (unregistered)

    The programmer explicitly checks for and discards all the possible statuses? And this isn't a wtf? Wtf is wrong with you people? TRWTF is you points /Kitchener

    The other oddities are just the sugar sprinkled on top.

  • Steve H. (unregistered)

    No one else thought that the original developer might have been trying to increase his SLOC?

  • F (unregistered) in reply to Scott
    Scott:
    I'm a little worried about how many people are missing the problem with this code.

    A little worried? There must be millions of people who haven't even read it yet.

  • Nagesh Kukunoor (unregistered) in reply to Nagesh
    Nagesh:
    Nagesh Kukunoor:
    trwtf:
    empathic:
    And not being Hitler isn't yours, is it? Stop being racist, dude, calm down.
    You're the one who brought Hitler into the conversation. Isn't there some rule about how it's the dumbest people with the weakest arguments who are the first to raise comparisons to Hitler?
    +1 for identifying a case of "Reductio ad Hitlerum" (and no, it's not Godwin's Law, that's something different). I agree, as soon as you invoke Hitler your argument is completely invalid and your opinion is about as useful as an offshore coding team.

    Please stop using my name.

    Registering my name does not give you the right to impersonate me. I am real Nagesh Kukunoor.

  • (cs) in reply to Jay
    Jay:
    Nagesh:
    trwtf:
    Nagesh:
    trwtf:
    Nagesh:
    I am first. Am I not? Akismet, whatever you are. Damn Yuo.
    Indian coders are always first but you have to ask yourself - do you want it done fast or do you want it done right??? I'm guessing your code is about as useful as your comment.

    As for today's WTF, I've seen people make superfluous checks plenty of times before but I can't recall ever seeing code that checks the same variable twice on the same line. That's... interesting.

    That's cos of timeszone dear.

    English isn't your strong suit, is it?

    After being ruled by English for several decades, I decided to get back at them by slaughtering their language. Call me Daniel Webster of Hyderabad.

    Oh well. Your English is probably better than my Urdu anyway.

    A lot of people in Hyderabad speak it, but I don't. Hindi is sufficient for communication.

  • (cs) in reply to Nagesh Kukunoor
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    trwtf:
    empathic:
    And not being Hitler isn't yours, is it? Stop being racist, dude, calm down.
    You're the one who brought Hitler into the conversation. Isn't there some rule about how it's the dumbest people with the weakest arguments who are the first to raise comparisons to Hitler?
    +1 for identifying a case of "Reductio ad Hitlerum" (and no, it's not Godwin's Law, that's something different). I agree, as soon as you invoke Hitler your argument is completely invalid and your opinion is about as useful as an offshore coding team.

    Please stop using my name.

    Registering my name does not give you the right to impersonate me. I am real Nagesh Kukunoor.

    You want your butt kicked?

  • Ken B. (unregistered)

    To me, this looks like the code was originally like this:

    if ( httpReq.readyState == 0 )
        {
        ;
        }
    else if ( httpReq.readyState == 1 )
        {
        ;
        }
    else if ( httpReq.readyState == 2 )
        ...

    and a new programmer was told "change this to use switch/case instead".

  • Nagesh Kukunoor (unregistered) in reply to Nagesh
    Nagesh:
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    trwtf:
    empathic:
    And not being Hitler isn't yours, is it? Stop being racist, dude, calm down.
    You're the one who brought Hitler into the conversation. Isn't there some rule about how it's the dumbest people with the weakest arguments who are the first to raise comparisons to Hitler?
    +1 for identifying a case of "Reductio ad Hitlerum" (and no, it's not Godwin's Law, that's something different). I agree, as soon as you invoke Hitler your argument is completely invalid and your opinion is about as useful as an offshore coding team.

    Please stop using my name.

    Registering my name does not give you the right to impersonate me. I am real Nagesh Kukunoor.

    You want your butt kicked?

    AHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAAAAAHHHAHAHAHAHHAHAAAHAHAAHAHHAHAHAHAHAHHAAAA! Yes, I do. Your move!

    Seriously though, would you stop using my fucking name already? It's not big and it's not clever. Don't you have enough of an identity to use your own name? Are you some kind of schizo? You know what, I don't care; just grow up already, this is supposed to be a community of professionals and your behaviour is letting everyone down.

  • (cs)

    So the WTF is that the guy thought he might need to respond to other ready states and failed to put in a //TODO ?

    Addendum (2011-02-02 13:40): Nevermind - just noticed the ifs. This is the kind of retard that would fuck up a foreach.

  • (cs) in reply to Nagesh Kukunoor
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    trwtf:
    empathic:
    And not being Hitler isn't yours, is it? Stop being racist, dude, calm down.
    You're the one who brought Hitler into the conversation. Isn't there some rule about how it's the dumbest people with the weakest arguments who are the first to raise comparisons to Hitler?
    +1 for identifying a case of "Reductio ad Hitlerum" (and no, it's not Godwin's Law, that's something different). I agree, as soon as you invoke Hitler your argument is completely invalid and your opinion is about as useful as an offshore coding team.

    Please stop using my name.

    Registering my name does not give you the right to impersonate me. I am real Nagesh Kukunoor.

    You want your butt kicked?

    AHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAAAAAHHHAHAHAHAHHAHAAAHAHAAHAHHAHAHAHAHAHHAAAA! Yes, I do. Your move!

    Seriously though, would you stop using my fucking name already? It's not big and it's not clever. Don't you have enough of an identity to use your own name? Are you some kind of schizo? You know what, I don't care; just grow up already, this is supposed to be a community of professionals and your behaviour is letting everyone down.

    +10 for teaching life lessons.

  • CJS (unregistered)

    This is some serious double protection! I wonder if anyone told them wearing two condoms does NOT mean safer sex...

  • Robb (unregistered)

    httpRequest: "I have altered the state, pray that I do not alter it any further"

  • airdrik (unregistered) in reply to Nagesh Kukunoor
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    On the one hand you both look like trolls (especially when you sit and flame each other over the use of a name) On the other hand, ever thought of the possibility that two people might actually have the same name? Oh, yeah that's ludicrous! There's never any more than one person at any time who has a given name!

    Of course TRWTF is thinking that this place is supposed to be a community of professionals.

  • ÃÆâ€â„ (unregistered)

    He's just future-proofing his code. If they decide to make readystate==3 do something, bam, he has a place to do that.

  • ÃÆâ€à (unregistered) in reply to Nagesh Kukunoor
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    trwtf:
    empathic:
    And not being Hitler isn't yours, is it? Stop being racist, dude, calm down.
    You're the one who brought Hitler into the conversation. Isn't there some rule about how it's the dumbest people with the weakest arguments who are the first to raise comparisons to Hitler?
    +1 for identifying a case of "Reductio ad Hitlerum" (and no, it's not Godwin's Law, that's something different). I agree, as soon as you invoke Hitler your argument is completely invalid and your opinion is about as useful as an offshore coding team.

    Please stop using my name.

    Registering my name does not give you the right to impersonate me. I am real Nagesh Kukunoor.

    You want your butt kicked?

    AHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAAAAAHHHAHAHAHAHHAHAAAHAHAAHAHHAHAHAHAHAHHAAAA! Yes, I do. Your move!

    Seriously though, would you stop using my fucking name already? It's not big and it's not clever. Don't you have enough of an identity to use your own name? Are you some kind of schizo? You know what, I don't care; just grow up already, this is supposed to be a community of professionals and your behaviour is letting everyone down.

    Both of you, if you're gonna use my name, can you at least not anglicize it? k thx bye

  • hose (unregistered)

    Askimet.... Ahhh.... wasted 10min of my valuable time on participating on this stupid post.... there you go: my personal wtf of the day!

  • trtrwtf (unregistered) in reply to empathic
    empathic:
    trwtf:
    Nagesh:
    trwtf:
    Nagesh:
    I am first. Am I not? Akismet, whatever you are. Damn Yuo.
    Indian coders are always first but you have to ask yourself - do you want it done fast or do you want it done right??? I'm guessing your code is about as useful as your comment.

    As for today's WTF, I've seen people make superfluous checks plenty of times before but I can't recall ever seeing code that checks the same variable twice on the same line. That's... interesting.

    That's cos of timeszone dear.

    English isn't your strong suit, is it?

    And not being Hitler isn't yours, is it? Stop being racist, dude, calm down.

    I guess I've made it - I've got my own imposter. Time for a handle refresh.

  • qbolec (unregistered)

    Several people mentioned that already, but I share their ideas:

    1. the coder probably thought that Aysynchronous Javascript = multithreaded and wanted to be on the safe side (still, he should have used some locks then). I think that we could give him some credit for realizing the race condition problem.
    2. the coder didn't know that switch and case require breaks, and added ifs to make it work. IMHO this is stupid language design and smells like GOTO to me. Still, using language structures that you do not understand is unwise( Btw. did you know that break statement in PHP takes a numeric paramater that can be a variable, that says how many levels of loops/switches you want to escape?). This does not explain why he addded breaks inside ifs.
    3. the coder wanted to use ENUMs for status codes, but a) JS does not have ENUMs, b) JS does not allow case labels to be variables. This does not explain literal integer values in the code, but perhaps those got redacted.
    4. the coder likes variables to have limited scopes, and figured out that using if(){} could be useful for that, but did not know that JS puts all variables inside the function into same scope.

    So TRWTF is JS : a difficult functional language, that teenages try to use to grow from imperative spaggetti script kiddies to Object Oriented programming, which obviously must fail.

    My theory: there would be less script kiddies if JS actually was multithreaded, as none of them could ever write a onmousemove handler correctly

  • (cs) in reply to qbolec
    qbolec:
    My theory: there would be less script kiddies if JS actually was multithreaded, as none of them could ever write a onmousemove handler correctly
    And the few that could would no longer be script kiddies.
  • ÃÆâ€â„ (unregistered) in reply to qbolec
    qbolec:
    So TRWTF is JS : a difficult functional language, that I try to use to grow from imperative spaggetti script kiddies to Object Oriented programming, which obviously must fail.

    If it was so difficult for you, you should have just gone to PHP like everyone else.

  • (cs) in reply to airdrik
    airdrik:
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    On the one hand you both look like trolls (especially when you sit and flame each other over the use of a name) On the other hand, ever thought of the possibility that two people might actually have the same name? Oh, yeah that's ludicrous! There's never any more than one person at any time who has a given name!

    Of course TRWTF is thinking that this place is supposed to be a community of professionals.

    Indeed. This is in fact a community of slightly-unprofessional developers making fun of the chronically incompetent.

    In IT, you often have to choose between Competent and Professional. Which do you prefer?

  • Gunslinger (unregistered)

    Since this only realy makes sure, it's fine. Now if it really made sure, that'd be a different story.

  • Gunslinger (unregistered) in reply to Scott
    Scott:
    I'm a little worried about how many people are missing the problem with this code.

    I'm totally not surprised though.

  • Gunslinger (unregistered) in reply to Gary
    Gary:
    And for breaking if and for loops: why not just write the ifs in the right order and use a while/do loop with a counter?

    Seriously? Go back to school, right now. Quit your job, don't do any coding, until you learn the answer to that question.

  • Kukesh Nagunoor (unregistered) in reply to hoodaticus
    hoodaticus:
    airdrik:
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    On the one hand you both look like trolls (especially when you sit and flame each other over the use of a name) On the other hand, ever thought of the possibility that two people might actually have the same name? Oh, yeah that's ludicrous! There's never any more than one person at any time who has a given name!

    Of course TRWTF is thinking that this place is supposed to be a community of professionals.

    Indeed. This is in fact a community of slightly-unprofessional developers making fun of the chronically incompetent.

    In IT, you often have to choose between Competent and Professional. Which do you prefer?

    Neither. I'll take cheap.

  • Sudo (unregistered) in reply to anon
    anon:
    TRWTF is realy
    Seconded.
  • Dave (unregistered) in reply to qbolec
    qbolec:
    Several people mentioned that already, but I share their ideas: 1. the coder probably thought that Aysynchronous Javascript = multithreaded and wanted to be on the safe side (still, he should have used some locks then) -snip-

    No, the real wtf here is that there is a page and a half of comments before someone mentioned the word 'lock'

  • blah (unregistered) in reply to Sudo
    Sudo:
    anon:
    TRWTF is realy
    Seconded.
    Thirded. Does Alex have any shame?
  • lomendil (unregistered) in reply to Gunslinger
    Gunslinger:
    Scott:
    I'm a little worried about how many people are missing the problem with this code.

    I'm totally not surprised though.

    Yeah, something happened around here where the serious coder:troll ratio went way down hill.

  • gratuitous_arp (unregistered)

    Ready? Set? Ready? Set? GO!

    Everyone who didn't wait is disqualified.

  • Curious George (unregistered) in reply to zdux
    zdux:
    Here you go: My manager "fixed" my code in a wtfy way. The problem was that in IE printing a table of data which spanned more than a single page would reprint the same data starting on the second page. ...snip... I fully suspect the reason this guy had been promoted to manager was to keep him out of the code *sigh
    +1 best anecdote
  • Curious George (unregistered) in reply to amischiefr
    amischiefr:
    Slow day in the wtf community. Maybe next we can talk about how somebody used a variable named 'ret' for a return value.
    Yeah, but what the heck. It is a wtf, and provided light reading while demonstrating a logic problem or two to the noobs.
  • iMalc (unregistered)

    Methinks the author had his brain switched off.

  • Not of this Earth (unregistered) in reply to iMalc

    TRWTF are incompetent morons writing CodeSOD comments. Include me if you wish, but whatever.

  • ziggy wtfdust (unregistered)

    TRWTF is these comments. I really can't tell if most of them are supposed to be funny, trolling, or just really bad programmers demonstrating their crappiness.

    If you need to do multiple operations based on the value of status at some point, and status can change, then you copy it's value to a local variable first and then do all operations using that variable, not the function. Congrats, your code is now immune to dozens of strange things that might happen if it changes mid run. No locking, no "framework" wtf ever that meant, no worries about threads, events, synchronization, garbage collection, fifth normal form and god knows whatever else has clouded the brains of the people posting here.

  • Tovaritch (unregistered) in reply to trwtf
    trwtf:
    As for today's WTF, I've seen people make superfluous checks plenty of times before but I can't recall ever seeing code that checks the same variable twice on the same line. That's... interesting.
    Saw it in some age old production code just this morning in the form
    if(var==true) return var ? true : false;
    In other words, two more checks than needed. Judging by the log it was committed by a student intern, but I blame the management since "code-review" at the time was based on the "if it don't break, don't touch it"-principle.
  • kraii (unregistered)

    just because you're paranoid, don't mean javascript ain't after you

  • ted (unregistered) in reply to airdrik
    airdrik:
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    Nagesh:
    Nagesh Kukunoor:
    On the one hand you both look like trolls (especially when you sit and flame each other over the use of a name) On the other hand, ever thought of the possibility that two people might actually have the same name? Oh, yeah that's ludicrous! There's never any more than one person at any time who has a given name!

    Of course TRWTF is thinking that this place is supposed to be a community of professionals.

    Option 3: they are the same person

  • empathic (unregistered) in reply to ziggy wtfdust
    ziggy wtfdust:
    TRWTF is these comments. I really can't tell if most of them are supposed to be funny, trolling, or just really bad programmers demonstrating their crappiness.

    If you need to do multiple operations based on the value of status at some point, and status can change, then you copy it's value to a local variable first and then do all operations using that variable, not the function. Congrats, your code is now immune to dozens of strange things that might happen if it changes mid run. No locking, no "framework" wtf ever that meant, no worries about threads, events, synchronization, garbage collection, fifth normal form and god knows whatever else has clouded the brains of the people posting here.

    TRRWTF is that you american communist haven't read the comments properly and base a fragile argumentation on top of your fragmented observations:

    Or use a local variable to store the numeric code?

    Whoa. This site is full of european retards, hail USA, hail. God save the USA, may the green cards go out of stock soon.

    Go fuck yourself, pothead.

  • (cs)

    perhaps is not a WTF because the programmer thought that, in the future, some logic will be included in the others cases of the swicth statement

  • Gary (unregistered) in reply to Gunslinger
    Gunslinger:
    Gary:
    And for breaking if and for loops: why not just write the ifs in the right order and use a while/do loop with a counter?

    Seriously? Go back to school, right now. Quit your job, don't do any coding, until you learn the answer to that question.

    So how shall I implement that directive?

    for (var school=0;school<maxSchool;school++) {
      if (checkUnderstandBreak()) break;
      learn(school)
    }
    if (!checkUnderstandBreak) alert('you still don't get it');
    </pre>
    

    or

    while (!checkUnderstandBreak && school < maxSchool) learn(school++);
    

    Fear not, I don't really code for a living. And I make buckets more than you coders! Hurrah!

Leave a comment on “Sturdy Switch”

Log In or post as a guest

Replying to comment #336575:

« Return to Article