62

I have a question about this question I made, Which code is more CPU/memory efficient when used with a Garbage Collected language?.

It seems that it has no research effort, but, it does. I read a ton of articles about garbage collectors, generations and memory management before making that question. I'm not an expert, but I put a lot of effort learning this stuff by myself. So, I wanted to make a toy simple example about how I thought memory management could be made, and the result were four downvotes.

Lately I feel Stack Overflow has become hostile to inexperienced programmers. I searched the site, and I found out that many questions that could be answered with a simple Google search got a lot of upvotes.

(At least, making my question was worth it: I learned a lot of new stuff about garbage collection and compiler's optimization :D)

18
  • 2
    Just a point : the most recent question you link is close to 3 years old. Rules evolve I guess. I personally wouldn't have downvoted, but a) the toy example might have make it look easier than it is and b) 2 downvotes isn't horrible. It was countered by 2 upvotes already.
    – Patrice
    Commented Jan 10, 2015 at 17:03
  • 8
    Pretty much the way SO runs; you can get fast answers for sure, but forums are much more "friendlier".
    – Brett
    Commented Jan 10, 2015 at 17:06
  • 6
    @Broken_window it's possibly the meta effect : you put your question on meta, it has more visibility.
    – Patrice
    Commented Jan 10, 2015 at 17:35
  • 7
    And note that the meta effect can drive the votes either way. Commented Jan 10, 2015 at 17:36
  • 4
    Most of the questions with the highest number of votes are the questions which address problems starting with - How to.., you will easily find them in the documentation, but when a normal user facing the same error googles it, he is interested to click on the link which shows how this problem has been solved in the past (SO) rather than how this problem is to be avoided by doing it correctly (documentation). Once he finds the answer useful, he upvotes it. Questions involving research on the other hand, mostly, are understood and answered only by a section of the community.
    – BatScream
    Commented Jan 11, 2015 at 0:00
  • 20
    "Lately I feel SO has become hostile to inexperienced programmers" -- this is true one can't deny it. Commented Jan 11, 2015 at 13:15
  • 6
    If you want to beef up the research behind your question you should have added citations. Regardless I agree with this question being closed, especially the way you have asked it. If with regard to GC-languages generally it is too broad, if with regard to Java specifically, perhaps consulting the Java specification is your next step. And closing this question has nothing to do with being "hostile to inexperienced programmers", that's just self-pity.
    – Dexygen
    Commented Jan 11, 2015 at 14:11
  • 24
    "I did so much research" - well, to be blunt, your research didn't seem to get you far and seemed to be in the entirely wrong direction as you researched about garbage collection when your question has more to do with very basic compiler optimizations. Your question is also rather broad as you don't seem to know about those simple optimizations given the example you've produced. So you're getting downvoted because the result of your research is bad regardless of your effort which we can't measure anyways.
    – l4mpi
    Commented Jan 12, 2015 at 11:18
  • 24
    The question is essentially "I have read tons of articles about dogs and now I wonder which one of these two dogs produces the most hair?", followed by two pictures of cars. And since nobody can answer that question in a reasonable manner, you'll get down-votes and close votes. The question was correctly closed as "unclear what you are asking" and I'm not sure why people are casting reopen votes for.
    – Lundin
    Commented Jan 12, 2015 at 14:36
  • 15
    "Lately I feel SO has become hostile to inexperienced programmers" -I agree. It is also getting nasty to people PERCEIVED as inexperienced (i.e. Low SO scores). I had someone downvote a question that I asked, was never answered, then I answered it with a solution that I found outside SO. I really feel as if Fonzie has done his jump, here. I am starting to find more and more answers in venues other than SO, and don't really feel like being insulted for no apparent reason. If you downvote, you should be forced to explain it Commented Jan 12, 2015 at 15:02
  • 9
    @MAGSHARE personal anectodes have little to do with this. Forcing people to explain DVs has been declined thousands of times for good reasons (search meta.SO and meta.SE for more on this). Also, if you think DVs are personal insults then your attitude is the problem here. Furthermore, the two last answer DVs (didn't find any on questions) don't seem unreasonable; one is explained (your self-answer solved your specific problem but not the general question) and the other (on "what are intervals") is probably because you've posted a whole tutorial instead of answering the specific question.
    – l4mpi
    Commented Jan 12, 2015 at 15:22
  • 2
    No intention to offend anyone, with ALL the respect, sometimes SO community is giving me the impression that effort is not-only awarded but also harshly criticized, especially if you are not a high-rep user. Tons of effort to give appropriate questions or answers go to garbage, including questions that are of general interest, while opinion-based questions of older times (and with lots of up-votes) are still praised. We should not speak or think (only) in code, unless we want a community of compilers running code in their mind and giving out error messages and suggestions. Commented Jan 12, 2015 at 15:30
  • 1
    Shrug. Whatever. The tutorial is not supposed to be the answer. It's merely the result of about six hours of personal research. I just wanted to share it because I consider this community as valuable to me, and I believe in giving back. You're welcome. Sorry that it isn't what you want here. I also changed the TITLE of the original post, because the DVer had a point. However, it's pretty obvious the DV was a fit of pique (BTW: That answer trumps the hell out of the new dylib capability). I couldn't find it on SO, so researched, prototyped and imported it to SO. You're welcome. Commented Jan 12, 2015 at 15:57
  • 4
    @l4mpi comment that DV's are not insults is really to the point here. DV's are to help you realize that your question needs improvement. Ignorance in how to improve your post might be frustrating, but posting to SO is a skill like any other and must be worked on.
    – crthompson
    Commented Jan 12, 2015 at 21:29
  • 2
    @Broken_Window I think you are correct: they are very subjective. Because of this meta post, your question is getting attention and now has 40 upvotes and 30 downvotes, which is a bit extreme. Normally, all votes tend to go in one direction or the other. Subjective indeed.
    – Lundin
    Commented Jan 13, 2015 at 15:33

4 Answers 4

89

First, your question only has two downvotes that I can see. Maybe others were removed after the edits?

It seems that it has no research effort, but, it does have. I read a ton of articles about garbage collectors, generations and memory management before making that question.

That effort doesn't really show in your question. We can't know what research you've done unless you tell us. What articles did you read? What did they say that you're unsure of?

Lately I feel SO has become hostile to inexperienced programmers.

I don't think SO is hostile to inexperienced programmers so much as it is hostile to unclear or incomplete questions. Inexperienced programmers just happen to ask a lot of those. When new users ask great questions, they generally tend to get upvoted.

I searched the site and I found out that many questions that could be answered with a simple Google search got a lot of up votes.

The questions you link to have been here for years. They were helpful to a lot of people searching with the same question in that time, so they've accumulated a lot of upvotes.

In addition to those points, people are commenting on your question telling you what's wrong with it. Why not use that feedback to improve it, or at least learn from it?

10
  • 3
    You're right in one point I didn't notice: the simple mention of Gen0, GC, etc doesn't show the effort behind. I'll be more careful next time :) Commented Jan 10, 2015 at 17:34
  • 8
    @Broken_Window: No need to wait until next time: If you think that your question is worth being kept on Stack Overflow, then you can still edit your post in order to improve it. Please try to address all criticism raised in the comments. If you are done with that, then you can ask to remove the on hold lock.
    – honk
    Commented Jan 11, 2015 at 14:21
  • Bill, it looks like it has 13 downvotes - it just is offset by 11 upvotes. At least at this time.
    – corsiKa
    Commented Jan 12, 2015 at 14:25
  • @corsiKa That's the Meta effect. It was at +3/-2 at the time I wrote this answer. (If I remember correctly.)
    – Bill the Lizard Mod
    Commented Jan 12, 2015 at 14:27
  • 18
    +10000 Can we bold the second point? We are far more hostile towards terrible questions than the new users/programmers who typically ask them. Unfortunately, people take it personally. Commented Jan 12, 2015 at 17:28
  • 1
    Of course it's hostile to inexperienced programmers. Most inexperienced programmers I know wouldn't ask a question on SO; nor would I if I hadn't learned the manner in which one should phase a particular question. Having said that, casual users and inexperienced programmers are more likely to ask a question that is localised and not useful to subsequent readers; so there's two sides to it, I guess. The fact that the question asked by the OP went from something like -13 to +10 shows just how much BS there is in the system.
    – Stumbler
    Commented Jan 13, 2015 at 9:32
  • 9
    @Duncan I like how the SO community wants it's questions. I actually solved three problems I was about to write a question on, by trying to 'generalize' them enough to make them valid for SO. In two cases it led me to the realization that I'm trying to do something very stupid. In the third case I just rewrote the complete thing because it was really ugly code. What ever the error was in the ugly code, it worked after the rewrite. Commented Jan 13, 2015 at 12:11
  • 4
    @Steffen Winkler: If only more people had the same attitude as you.
    – BoltClock Mod
    Commented Jan 13, 2015 at 14:40
  • @BoltClock well, to be honest, I wish I had the intelligence/knowledge that would've prevented those situations from happening in the first place ;) but thank you for the assumed compliment! Wish more people were as nice as you are ;) Commented Jan 13, 2015 at 14:50
  • 3
    @Steffen Winkler: It is a compliment indeed :) Too many people lack the patience and resolution to approach problems the way you do - which is too bad because programming is one of those things that really takes quite a lot of patience.
    – BoltClock Mod
    Commented Jan 13, 2015 at 14:59
12

This question makes a lot of incorrect assumptions. For example the GC is not involved with primitive local variables at all. Also, all of this code will be deleted by the optimizer because it has no side-effects.

From an answering user's standpoint it is always hard to rescue such questions and say something useful about them.

This is not really your fault because your skills were not enough to recognize these false assumptions.

Maybe your question was too broad as well. That amplifies the effect of those false assumptions and makes it hard to tell what you are really interested in.

If in doubt whether a question is clear and targeted enough - don't ask (yet). Wait until you are skilled enough to at least ask the right question. You are not entitled to ask just by the fact that you do not know something. The question must be "good" as well. If not it's not for Stack Overflow.

Ask the rubber duck.

5
  • 10
    "Wait until you are skilled enough to at least ask the right question." - That's tricky. All questions imply a degree of ignorance to a point. There has to be a cutoff when you decide to ask for help, humbly knowing you probably should know the answer, but need a second set of eyes, or some greater working experience to unlock things. Having someone spend 5 minutes and read a question might save days or weeks of fruitless searching with unknown search terms. You are right though, in that it would HELP the asker in most cases and most times, answer the question without having to post it.
    – peege
    Commented Jan 12, 2015 at 17:30
  • 2
    Your answer here implies that the OP was downvoted for lack of knowledge, which doesn't seem to be the case. They were probably downvoted because of the way they asked the question. In my opinion, you shouldn't downvote for lack of knowledge, but rather how much effort did they put into the question, how well did they explain what they're asking, did they violate any SO rules etc.
    – mason
    Commented Jan 12, 2015 at 18:23
  • 3
    @peege: I agree with you. But I think that the quality of questions could be improved if people who are inexperienced in asking questions asked their question out loud to their rubber duck before posting it.
    – honk
    Commented Jan 12, 2015 at 21:09
  • 1
    No doubt. I know I would have asked more questions, but In attempting to get the most info before posting, I solve it myself. Because of that fact,I've also probably avoided seeking help when I really should have.
    – peege
    Commented Jan 12, 2015 at 21:12
  • 1
    @mason not lack of knowledge. Reason is creating an unanswerable question because he couldn't even ask (let alone answer).
    – usr
    Commented Jan 13, 2015 at 9:09
9

The point of the downvotes I think is that you're asking the wrong questions, which shows a lack of knowledge, which can be perceived as a lack of research.

From your title: "Which code is more CPU/memory efficient?" in itself already is a red flag. Usually when that is the actual question, the question is poor (as in: "is for faster than foreach?") or it comes down to StringBuilder versus string concatenation. Also, you can benchmark it yourself so you don't have to, or the code involves disk or even network I/O and you shouldn't even ask it.

But alright, let's click the title and read the question.

"I would say both codes consume the same amount of memory" - we're talking garbage-collected languages here, where the runtime itself already takes up 10+ MB of RAM to get your application running. Are you really interested in the memory load of one 32-bit integer, and what memory region specifically do you think it will reside in?

"Code 1 is more CPU efficient because it creates and allocates variable a just once". Did you benchmark that? Do you know what compilers do?

"keeping variable a inside the loop makes it belongs to Gen0" - where did you read this?

All in all, the confusion only becomes greater while reading your question, and the proper answer will become longer and longer to write in order to correct all misconceptions.

When learning about a subject, it helps to drill down to the smallest subset of the problem you're trying to solve.

Your first question should be "When do local value types get garbage collected?", which is answered in Do value types get Garbage collected? and How Garbage collector Will behave on value type and Reference type, to which the answer is: that's an implementation detail, but usually when you return from the method or when the runtime can determine that the reference will not be accessed again and it feels like doing a garbage collection run.

Your next question should be "Will an unused local variable be present in my compiled code?", which is answered in Can a conforming C# compiler optimize away a local (but unused) variable if it is the only strong reference to an object? and Watch unused Local Variable is impossible? Why?.

Then finally, you can ask "Is it faster to declare a variable inside a loop?" (which, again, is a poor question in itself, the proper question would be "Does the compiler move a variable declaration out of a loop?") which is answered in Declaring a variable inside or outside an foreach loop: which is faster/better?: it doesn't matter.

Instead of typing all this, most people sigh, shrug their shoulders, down- or closevote and move on.

3
  • 1
    Seems there are lots of pity up- and re-open-voters too though. Commented Jan 13, 2015 at 12:13
  • 3
    @Deduplicator people sometimes seem to think up- and reopen-votes are for questions they know the answer to.
    – CodeCaster
    Commented Jan 13, 2015 at 12:17
  • I find this answer very helpful. It's a perfect explanation, and I am grateful to CodeCaster for typing it up. Thinking in these terms breaks down ambiguity and goes a long way to solving the problem causing a question to be asked at all.
    – peege
    Commented Jan 13, 2015 at 14:08
0

I think the biggest frustration you're experiencing here is over points. And that's a difficult topic.

For those of us with a limited number of points, our lack of points limits our access to the site. On the otherhand those who have so many points they have attained all the privileges, points are a meaningless number that has been accumulated.

Yes you did get a ton of downvotes, you'd probably find very few of them came from people who viewed points as meaning anything. The people casting those votes are trying to protect the quality of the site, and felt your question did not aspire to that standard.

You also got a ton of good information. If that's really what you were seeking take heart! There's tons more where that came from on StackOverflow.

Don't sweat the downvotes and enjoy the info. https://meta.stackoverflow.com/a/266670/2642059

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .