Hacker News new | comments | ask | show | jobs | submit login

I'll probably get downvoted, but I think elaborate real-life analogies like this are more likely to confuse novices than help them.

A better explanation in my opinion is to draw a diagram of a stack and showing that returning from a function just decreases a pointer. C++ programs don't scrub the top of the stack once you finish a function because it is a waste of time.

If another function was called before the 2nd call to foo(), then the variable on the stack would be overwritten.




The analogy is supposed to explain the concept of undefined behavior, not the details of memory management.

If you are used to safe languages, the concept of undefined behavior might be confusing. In those languages, an operation is either allowed or not allowed, and if it is allowed it has well-defined behavior. In C a number of operations does not have well-defined results, but is still technically possible to perform, or might be possible depending on circumstances. But you shouldn't use them. The analogy is supposed to explain that.


undefined behavior is fun. All this stuff gets a lot more interesting in microcontrollers, where security is not an issue and you sometimes have to manage memory directly and store data between power cycles.


Let me preface this by saying I am not attacking you just stating an opinion about the sentiment

Thats the exact type of thinking that keeps so many people away from programming and computer science.

A nice accessible answer that helps a person make a logical leap in the right direction is so much more important to a novice than pedantry.

Its not a perfect answer but to a person who has no clue whats going its a lot more helpful to get some idea


While that is more accurate and I think that programmers should understand how computers work, as well as C calling conventions, in this case the analogy helps. People who know what the stack is (other than something that can be overflowed) as well as how functions are implemented would likely never think to ask this question. By the time you give the satisfactory "real" answer, you've written the better part of an intro architecture lecture (at my school, I think we probably had 2 or 3 lectures and a lab to get to this point, with other digressions).

The real explanation would also be less complete than the analogy as going into the "construction of a football stadium", etc. would have to consider optimizing compilers, virtual memory, and the other things that could get really mucked up. The analogy is accessible even to people who don't program, rather than to just those who have seen %ebp and %esp.


Sorry for the off-topic rant, but is it only me or are people, who start with "I'll probably get downvoted, but ...", never actually downvoted? Maybe it's some kind of reverse psychology, like parents who tell their children the opposite of what they actually want them to do. Or maybe the downvoting behavior on HN is actually better then people think and different options are actually valued.


I've noticed that when people start their comments with "sorry for X," or "is it only me . . ." they tend to get upvoted. This could be another instance of the same reverse psychology you posit.


Some people (I'm one) make a point of always downvoting people who say "I know I'll get downvoted for this, but ...". (I'll make an exception if what they write is so good I'd have upvoted it; in that case I'll just not upvote it.) The less useful that sort of sympathy-fishing is, the better HN will be.


Similarly, I will often downvote comments that complain about being downvoted, either as a reply or an edit. I find whining about votes detracts from the discussion and has no place here and therefore is worth a downvote. People need to become less concerned about their scores - if people find a comment is valuable, it will be upvoted. If not, it may be downvoted and complaining about being downvoted makes it less valuable, not more.

Of course, by my own logic, this comment should also be downvoted purely because it is a meta comment, is off-topic and detracts from the actual discussion. Hell, if I could, I'd do it myself ;-)


I'm curious if you considered that the reason people preamble their posts with this is because they have gotten multiple downvotes in the past for something they said which was reasonable? My understanding is that downvotes should not be cast for dissenting opinions or unpopular but logical statements. However, my experience with the site is that this happens from time to time. Thankfully, there is sufficient traffic so that the situation often (but not always) rectifies it self .. i.e. people tend to upvote good comments. I'm relatively new to the site so am still trying to figure it out.

To this end, I feel the cap of -10 on downvotes was a great idea. It lets someone post an unpopular (but hopefully logically sound) argument with the knowledge that they will lose a capped amount of karma.


"I know I'll get downvoted" is also sometimes code for "this post is so awesome you probably won't understand it, but go ahead and downvote because I don't care about little minded people like you."


It certainly can happen that something reasonable gets a lot of downvotes. But not nearly as often as it happens that something unreasonable (or stupid or irrelevant or otherwise unhelpful) gets a lot of downvotes even though its author thinks it's a useful contribution.

I think "I know I'll get downvoted ..." usually just indicates (not a long tragic history of getting downvoted for insightful comments, but) roughly what it says: the author expects to get downvotes -- and probably hopes to get fewer by saying s/he expects them. HN is better off without those preambles because (1) they're a waste of space -- learning that the author of something expected downvotes tells you nothing useful -- and (2) they distort the scoring system, which (for all its flaws) does help to order comments well and identify ones that aren't going to be worth reading.


Also, the only reason the author would expect their comment to be downvoted is because 1) its insightful, but unpopular and 2) because the author knows right well that the post adds little value, is off-topic or detracts from the conversation.

If its #1, then you must clearly state your argument. A well thought out, but unpopular, opinion normally doesn't get as many downvotes as a not so well thought out opinion.

If its #2, then maybe the author should simply refrain from posting.


> To this end, I feel the cap of -10 on downvotes was a great idea.

Is there really such a cap? Back when comment scores were displayed, there was a minimum display score, but actual score could go far below it, with no apparent minimum. Such a cap would be/is a very good idea, of course.


I agree, in particular, that the image of how the stack works is critical for really understanding the problem. The hotel analogy is nice, but doesn't help much in generalizing or extrapolating to other issues.


Yeah, the hotel room analogy breaks as soon as you realize that visiting some completely other hotel room will already overwrite that variable in the first one.

But it was a fun story, though.


Analogies like this are stepping stones, not the destination. I try to both use an analogy and give the fullest explanation that I think they can handle. The analogy tells them the structure of the complete answer. The complete answer often has concepts that are new to them, and the more unknowns in something, the harder it is to learn. The analogy allows them to understand the structure of the reason, which removes an unknown.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: