Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

I see a lot of answers where a user just provides the code that accomplishes what the asker wanted. I don't think this is really the purpose of Stack Overflow, because people come here to become better programmers, and what good is it doing when people leave answers that the asker can simply copy/paste and get it to work? They're not learning anything so it has no value.

For example:

We don't answer questions only for the user who asked the question, but also for future users who come upon this question. What if that person wants to know how the snippet works?

I'd just like it if people who leave answers like this could take some time to explain what each snippet does. I try my best to do this on every answer I post where I provide code that does what the asker wants.

share|improve this question
As always, examples can be helpful in directing the discussion... hint – Shog9 Dec 4 '11 at 19:14
@Shog9: Thanks, looking for a few now. – Mystery Dec 4 '11 at 19:26
Most people come to StackOverflow to get answers, not to become better programmers. Sad, but true. – Oded Dec 4 '11 at 19:40
Added some examples. One of them is a question of mine where somebody provided this long code and I was not helped at all by it. @Oded: Probably, but for the group that comes here to improve, this is a big deal, isn't it? – Mystery Dec 4 '11 at 19:44
up vote 11 down vote accepted

A good answer will usually contain both; in adequate and balanced proportions.

But we don't only get perfectly balanced answers, here. Nature of the beast.

One risk with posting a correct but "short" answer is that someone else will start from your answer, flesh it out with details, and get voted/accepted for what amounts to a better answer... when the initial "spark" was yours.

Then again; often a short snippet of code really is all that is needed. I've seen some answers that went on and on and on with explanations of stuff that doesn't so much matter...

share|improve this answer

Everyone is free to up-vote whatever sort of answer they find useful. I'm not particularly fond of code-only answers either, but for certain questions they are enough.

Of course, it doesn't hurt to have competition. If someone wanted to post a second answer that took the code and explained it, they might well find themselves rewarded for it...

share|improve this answer
The upvotes are not so much a problem as the answer themselves...sure, people could just look up the stuff used in an answer, but it has more value when somebody tells you what everything does. Personally, I can't trust Google all the time for code, so it's good to hear it from somebody who knows what they're saying. – Mystery Dec 4 '11 at 19:40

This type of answer creates a vicious circle of i can haz teh codez questions. If an answer only gives code with no explanation, it makes users think that they will always be given code when they get stuck, and gives them no motivation to do research themselves.

share|improve this answer

True, but for the most part here, we're all programmers. I'd much rather receive an all-code answer (that works, grant it); than an all explanation answer with no code; at least I have a shot at diagnosing why it worked, and could do my own research. With all explanation and no code, I'm left to writing my own code, which, I was probably stuck on anyways if I came here...

So while I agree a balance would be nice and the optimal solution, having seen the opposite problem, I'd rather have the all-code answers.

Also, it depends on quality of the code; if the code has comments and longer, self-documenting variable names? It doesn't matter that it's an all-code solution. Or if it's a short simple sweet one-liner, that I or someone else obviously missed. I know if I spent extra time, to give you well-formatted, well-formed and properly named code, with comments, last thing I'm going to feel like doing is explaining the whole thing to you again in a post, in our world, time is money.

On the other hand, I can see your point if all you're getting is a pure code answer to a non-trivial problem, with no comments, poor formatting (especially in languages with poorer IDE's) and short, uninformative variable names, or code that simply doesn't work; that'd be very frustrating, and ultimately, not useful.

share|improve this answer

I think a good answer should include both documented code and a short explanation about the algorithm / logic of the solution.

share|improve this answer
Well, that's common sense. – Shadow Wizard Dec 29 '15 at 8:11
I totally agree with you on that, but there are cases in which the answer lacks a documentation or explanation. I had some cases I had to debug a code a few times to understand what it does, because there were no comments, no explanation and the variables were only one char length. – Liran Friedman Dec 29 '15 at 8:17

You must log in to answer this question.

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