Check your basics



  • Here's an interesting tale from the interview at StackOverflow.

    Since going to StackOverflow will no doubt trigger someone's PTSD, I'll post it here.

    Interviewer: Which is faster?

    while(1) {
    // some code
    }

    or

    while(2) {
    //some code
    }

    Nikole: Both have the same execution speed, as the expression inside while should finally evaluate to true or false. In this case, both evaluate to true and there are no extra conditional instructions inside the while condition . So, both will have the same speed of execution and I prefer while (1).

    Interviewer: Check your basics. while(1) is faster than while(2).

    I have no idea what "basics" he could be refering to.



  • #define 2 some_computation_not_known_at_compile_time



  • You forgot something. From SO: "This was an interview question asked by a senior manager."

    While I would not start at a company where a team leader or head of software development department would make the statement that while(1) is faster than while(2), senior managers need to be allowed some slack.

    They are supposed to manage things, knowing about the things they manage is not a requirement, especially for a senior manager.


  • BINNED

    9/10 would flame



  • TRWTF of course is StackOverflow:

    put on hold as off-topic by ... 23 hours ago
    This question appears to be off-topic. The users who voted to close gave this specific reason:
    "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting."

    Off-topic??? The question is tagged for "c", "performance" and "while-loop" and is a legitimate question someone new to C or C++ might ask.

    Brings to mind this blog post concerning StackOverflow.



  • I've read that post a while ago. Points out some legit problems with SO.

    On the other hand, even if SO doesn't generate interesting discussions anymore, it's still the best place to get coding help on the internet. Also, you don't have to participate in the rep games if you don't want to. I have over 800 rep there, and I only ever participated in a relatively obscurish niche of the site.



  • @cartman82 said:

    I have over 800 rep there

    I have 54. Ph33r my ePeen.



  • ...
    Impressive?


  • Discourse touched me in a no-no place

    @faoileag said:

    Off-topic??? The question is tagged for "c", "performance" and "while-loop" and is a legitimate question someone new to C or C++ might ask.

    There are at least two votes to reopen it, one of which is mine.



  • @Keith said:

    I have 54. Ph33r my ePeen.

    I have like 3 or something. I asked a question, got about 3 utterly worthless answers from idiots, then tried to answer my question, found I couldn't because (according to Jeff Atwood and his hit squad) it's utterly impossible to find your own answer if your reputation is less than 50 or something, so I had to edit the question to add the answer.

    Then I deleted my StackOverflow account and started recording a sleep tape to hypnotize me into believing that nothing that awful could really exist. Also lose weight.

    EDIT: HOLY CRAP I just revisited the question, and the people who posted the utterly worthless answers are apparently allowed to delete them, so now there's no evidence anybody ever tried to answer the question in the first place. (Except my question/answer mentions one of them by username.) Jesus Christ, that site's even worse than I thought.



  • I have no idea what "basics" he could be refering to.

    I think it's that 2 is 10 in binary, and 1 is 01, so that an equality comparison would have to check an extra bit...



  • I've read that post a while ago. Points out some legit problems with SO.

    On the other hand, even if SO doesn't generate interesting discussions anymore, it's still the best place to get coding help on the internet. Also, you don't have to participate in the rep games if you don't want to. I have over 800 rep there, and I only ever participated in a relatively obscurish niche of the site.

    I don't see SO as some monolithic Q/A site. I mean, yeah, it is. But it also supports communities. I see about 20 of the same people answering Haskell questions all the time (and yes, they see me).

    On the other hand, I had to go into the SQL ghetto a few days ago and got "LOL that's such a stupid design" because I was using "mutual constraints" and didn't know how to defer insertion until all the relevant keys got generated (or even what it was called, to find out on my own)


  • I survived the hour long Uno hand

    @blakeyrat said:

    EDIT: HOLY CRAP I just revisited the question, and the people who posted the utterly worthless answers are apparently allowed to delete them, so now there's no evidence anybody ever tried to answer the question in the first place.

    "Deleted" means "Hidden from people underneath an arbitrary rep threshold". Anyone who spends enough time on the site can still point and laugh, while people who come from google and lack accounts don't get bad advice



  • That brings up another complaint: the invisible and essentially random mechanics of their point system are impossible to comprehend. It's like the Git of web sites.

    Who knew, when I posted a question, I wouldn't be able to answer my own question. Oh but you can if you have enough reputation. Oh but you can't if the question hasn't been up 8 hours. Oh but you can if-- fuck it, I'll just edit the question to contain the answer.



  • SO scared me away because the few times I've tried to ask questions, somehow I didn't have the reputation to actually ask the question...or something like that. So I went elsewhere.



  • Depending on the language, the loops are actually undefined behavior. A few languages say that infinite loops have no meaning.



  • Wow.

    Though I suppose theoretically he could be right that while(1) IS faster than while(2), but only because while(1) MIGHT on some compilers be compiled to while(true) and either one could be optimized by the compiler directly for performance (where while(2) isn't because they aren't addressing that level of knuckleheadity)

    But... That's an incredible stretch, even for stack overflow.

    Good find.



  • @Captain said:

    I think it's that 2 is 10 in binary, and 1 is 01, so that an equality comparison would have to check an extra bit...

    Oh, I thought I was the only one who had a one-bit ALU on my processor.



  • @Matches said:

    Wow.

    Though I suppose theoretically he could be right that while(1) IS faster than while(2), but only because while(1) MIGHT on some compilers be compiled to while(true) and either one could be optimized by the compiler directly for performance (where while(2) isn't because they aren't addressing that level of knuckleheadity)

    But... That's an incredible stretch, even for stack overflow.

    Good find.

    Well the top answer on SO proofs that, on a practical level, there is no difference because it is compiled to an unconditional loop. Even with optimization turned off.
    Although I don't know if MSCC also does that.



  • @Zacrath said:

    there is no difference because it is compiled to an unconditional loop

    ... using whatever compiler the SO poster was using.

    I agree, a sane compiler should make it the same thing.

    Do all compilers in existence, or the OP's work compiler? No idea!

    Is it likely it does? Absolutely. Did it when the original manager tested it years and years ago (potentially)? Maybe.


  • BINNED

    If you think that's bad, you should spend some time at programmers.stackexchange. There are basically three types of questions that get posted:

    1. Questions with one obvious correct answer. The first person to post the correct answer gets most of the upvotes.
    2. Questions with no obvious correct answer, and the reason there is no obvious correct answer is because the question doesn't matter. These questions get lots of answers and eventually turn into community wikis.
    3. Questions that don't have one obvious correct answer because there is disagreement within the programmer community. These questions are routinely closed.

    The only questions of real interest and import fall under the third group, which can't be answered according to the site's rules, so the site is pretty much useless unless you're the type of person who likes to hear himself talk.



  • And so begins the mass exodus away from what.thedailywtf.com.


  • ♿ (Parody)

    @antiquarian said:

    The only questions of real interest and import fall under the third group

    Depends. The first group may not be interesting from your point of view, but it seems to be fulfilling what I understand to be the point of the stackexchange sites. I haven't hung out there, but I've been both sides of the ObviousDoor.


  • BINNED

    @boomzilla said:

    The first group may not be interesting from your point of view, but it seems to be fulfilling what I understand to be the point of the stackexchange sites.

    Not exactly disagreeing, but questions with just one obvious answer generally already have the answer available via a google search.


  • ♿ (Parody)

    Probably. I guess it depends on the obviousness. And I thought one of the goals was to consolidate that sort of thing into an "authoritative" site or whatever. Granted, that's partly marketing, but still.

    But yeah, closing actual interesting stuff is TRWTF.


  • BINNED

    @boomzilla said:

    And I thought one of the goals was to consolidate that sort of thing into an "authoritative" site or whatever.

    That's probably the worst thing. Having discussion about the third group of questions, especially if consensus answers could be reached, would have made programmers.se the authoritative site. It was a golden opportunity for Spolsky and Atwood that they basically threw away because apparently discussion is a barrier to answering questions.



  • @blakeyrat said:

    I have like 3 or something. I asked a question, got about 3 utterly worthless answers from idiots, then tried to answer my question, found I couldn't because (according to Jeff Atwood and his hit squad) it's utterly impossible to find your own answer if your reputation is less than 50 or something, so I had to edit the question to add the answer.

    Then I deleted my StackOverflow account and started recording a sleep tape to hypnotize me into believing that nothing that awful could really exist. Also lose weight.

    EDIT: HOLY CRAP I just revisited the question, and the people who posted the utterly worthless answers are apparently allowed to delete them, so now there's no evidence anybody ever tried to answer the question in the first place. (Except my question/answer mentions one of them by username.) Jesus Christ, that site's even worse than I thought.

    Ok, I'm confused.

    Just for curiosity's sake, I do the search for blakeyrat on SO and I find what seems to be the question in question:

    Before I get into the details of this problem, I'd like to make the situation clear. Our web analytics company works as a consultant for large sites, and (other than adding a single SCRIPT tag) we have no control over the pages themselves.

    Our existing script installs handlers using "old" way (a fancy version of element.onclick = blah; that also executes the original handler) which is completely unaware of "new" (addEventListener or attachEvent) handlers on the page. We'd like to fix this to make our script able to run on more sites without requiring as much custom development.

    The initial thought here was to have our own script use addEventListener/attachEvent, but this presents a problem: of the client's site sets a handler using the "old" way, it would wipe out the handler we installed the "new" way. Quick and dirty testing shows this happens in both IE7 and FF3, although I didn't test the whole range of browsers. There's also a risk that if we use the "new" way after the page's event handlers are already set, we could erase their handlers.

    So my question is: what safe technique can I use to add an event handler in Javascript using addEventListener/attachEvent that works regardless of how other event handlers on the page are installed?

    Please remember: we have no way of modifying the site that our script is installed on. (I have to emphasize that because the default answer to questions like this is always, "just rewrite the page to do everything the same way.")

    And the most upvoted and accepted answer is:

    Can you try your quick-and-dirty testing again? This doesn't happen for me in FF3.

    elem.onclick = function() { alert("foo"); };
    elem.addEventListener("click", function() { alert("bar"); }, false);
    Both handlers fire for me when I click on the element.

    I'm guessing you forgot the final boolean argument in addEventListener (whether to use the capture phase). I'm also guessing you forgot that IE's attachEvent needs onclick, not click.

    ... with the user blakeyrat accepting the answer with comment:

    Argh, you appear to be right. Apologies for the question, obviously the fault was a crappy test-case and not any specific bugs in the browser. (At least IE7 and FF3.) Thanks for pointing me in the right direction. – blakeyrat

    So.... what am I missing?



  • Oh I guess I've posted two questions to StackOverflow. Go figure.

    I didn't realize I ever used the "Blakeyrat" handle there. Probably should not have. Oh well.



  • @blakeyrat said:

    Oh I guess I've posted two questions to StackOverflow. Go figure.

    I didn't realize I ever used the "Blakeyrat" handle there. Probably should not have. Oh well.

    So, one bad experience, one good one.
    Making SO half good? Half bad?



  • I dunno, that Ilensky guy was kind of a dick. "Don't ever do that!!!" "I know, numbnuts, that's why I'm asking a question on how to stop doing that." He's like one of those assholes who makes fun of people at the gym for being out-of-shape-- they know they're out-of-shape, that's why they're in the gym!

    ... Anyway most likely all this reveals is SO sucked less in 2008 than it did when I tried it again in 2013. Probably because the "gamification" wasn't as awful back then. And I know for sure there weren't as many weird hidden arbitrary rules on what new users could and could not do.

    BTW, IIRC that whole thing was based on a goddamned junit test we had that was fudging the shit out of something which caused the click handler erasure. IIRC, that's basically when I gave up and decided "JavaScript is not unit testable if it touches the DOM." Because it isn't. Because the DOM is fucking terrible.


  • ♿ (Parody)

    @blakeyrat said:

    And I know for sure there weren't as many weird hidden arbitrary rules on what new users could and could not do.

    IIRC (and I lost interest in SO a while ago), they basically played whack-a-mole with perceived abuses and fine tuning. Not terribly different from what happened here with stuff like the new users and the bugs category.



  • Weren't you complaining about almost the same exact thing like two years ago on the CS forums here?



  • Ilensky? SO sucking less in 2008? Or junit? I don't know what "thing" you mean.

    But probably, yes.



  • Ambiguity is amazing.

    The onload event killing the hookup event.



  • @blakeyrat said:

    I dunno, that Ilensky guy was kind of a dick. "Don't ever do that!!!" "I know, numbnuts, that's why I'm asking a question on how to stop doing that." He's like one of those assholes who makes fun of people at the gym for being out-of-shape-- they know they're out-of-shape, that's why they're in the gym!

    Agreed. Seems like one of those guys who are trying to lecture you instead of solve your problem. And of course their bullshit pet peeve-level crap ups the response counter and suddenly your question receives 3 times less traffic and probably don't ever get the real answer.

    I'm always super conscious of this when answering questions. If the OP ever gets a lecture from me, it's after their immediate concern is resolved.

    @blakeyrat said:

    ... Anyway most likely all this reveals is SO sucked less in 2008 than it did when I tried it again in 2013. Probably because the "gamification" wasn't as awful back then. And I know for sure there weren't as many weird hidden arbitrary rules on what new users could and could not do.

    I wasn't active back then, but it seems there used to be a lot more fun discussion topics. SO these days might be more useful, I suppose, but there's little reason to just browse the site, looking for interesting topics. The main reason I'm answering questions in the first place is because I find it to be a good way of learning a new technology (once you get beyond the basics).



  • @cartman82 said:

    bullshit pet peeve-level crap ups the response counter and suddenly your question receives 3 times less traffic and probably don't ever get the real answer.

    I'm guilty of periodically using 'answer' to get more information for a problem I think I can help solve, primarily because you can't comment on the OP's post to get clarifying data unless you have X rep.



  • @Matches said:

    I'm guilty of periodically using 'answer' to get more information for a problem I think I can help solve, primarily because you can't comment on the OP's post to get clarifying data unless you have X rep.

    Ugh don't ever do that. The OP is better off with you moving on than posting a clarifying question as an answer.
    One of the weaknesses of SO's design, I suppose.



  • Not really, the questions are normally so vague they can't be answered. (Closed, too broad, closed off topic, closed won'tfix)



  • Yeah, the properly formatted questions, with easily workable examples / fiddles get answered in minutes. Once the rep vampires (like the guy from the article above) move on, all the questions left are:

    • "Sory my English poor. Please help"
      If I can decipher these, they could be decent. A coder who doesn't speak English is probably a timecard puncher, but not always.

    • "Hey guys, I'm mixing $obscure_technology1 with $obscure_technology2, and this strange error sometimes pop up. Any ideas?"
      I feel for these guys. We've all been there. Unfortunately, that doesn't mean I can actually help them.

    • "Just gimme the answers so I can go home!"
      These guys basically just blast out their train of thoughts, not caring about such basic courtesies as spelling, examples, code formatting etc. I intentionally don't answer them, even if I can. If they don't care about my time and effort, I don't care about their bullshit problem.

    • "I'm confused about everything"
      These people are trying to get into technology X, but don't know literally anything about it. It's like they open a blank document in a code editor, go to SO and ask "What now?". I would have been telling them to RTFM, but following my own rule about no bullshit answers, I usually just sorrowfully move on.

    And of course, an occasional actually good question, that rep vamps missed for whatever reason.


  • Discourse touched me in a no-no place

    There appears to be a missing "Do my homework for me" question category. Or doesn't SO attract lazy students?



  • @blakeyrat said:

    BTW, IIRC that whole thing was based on a goddamned junit test we had that was fudging the shit out of something which caused the click handler erasure. IIRC, that's basically when I gave up and decided "JavaScript is not unit testable if it touches the DOM." Because it isn't. Because the DOM is fucking terrible.

    unit tests and interpreted languages, ahahahahahahahah



  • Hey, I've written unit tests in PHP... well... what could be called unit tests....



  • @PJH said:

    There appears to be a missing "Do my homework for me" question category. Or doesn't SO attract lazy students?

    Surprisingly I haven't seen many of those. I suppose it would be a different story if I frequented technologies they teach in CS (Java, C#, C++...).


  • Discourse touched me in a no-no place

    @PJH said:

    There appears to be a missing "Do my homework for me" question category. Or doesn't SO attract lazy students?

    Those questions are in the “Delete with prejudice” category. They've got a half-life measured in a small number of minutes, especially in the high-traffic tags (like c++, java and c#).


  • Discourse touched me in a no-no place

    @antiquarian said:

    Not exactly disagreeing, but questions with just one obvious answer generally already have the answer available via a google search.

    Yes, and the whole point of Stack Exchange is to be the place that the obvious google search will find and to get the basic question answered. It's not Discourse a discussion board.



  • @dkf said:

    Yes, and the whole point of Stack Exchange is to be the place that the obvious google search will find and to get the basic question answered. It's not <s>Discourse</s> a discussion board.

    Jeff says Stack Overflow is a forum, therefore it is a forum.


  • Discourse touched me in a no-no place

    @Arantor said:

    Jeff says Stack Overflow is a forum, therefore it is a forum.

    No it isn't, and Jeff doesn't work there any more so what does he know? (I have more reputation too, but that's just ridiculous because I really don't hang out there very much except for tracking one lesser tag.)



  • @dkf said:

    No it isn't, and Jeff doesn't work there any more so what does he know? (I have more reputation too, but that's just ridiculous because I really don't hang out there very much except for tracking one lesser tag.)

    You, I and everyone here knows that SO is not a forum. But Jeff says it is a forum therefore it is a forum and he has used it as justification for some of Discourse's more interesting design choices.


  • Discourse touched me in a no-no place

    @Arantor said:

    justification for some of Discourse's more interesting design choices.

    interesting.com or interesting.cn?


  • ♿ (Parody)

    @Arantor said:

    Jeff says Stack Overflow is a forum, therefore it is a forum.

    When did he say that? I recall reading several times where he said it was not a place for pure discussion (i.e., a forum). Not that I'd be shocked if he said that as part of a rationalization of something Discourse related, but...


Log in to reply