46

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.

closed as off-topic by ale, Glorfindel, Ward, Nathan Tuggy, gnat Dec 11 '17 at 19:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question pertains only to a specific site in the Stack Exchange Network. Questions on Meta Stack Exchange should pertain to our network or software that drives it as a whole, within the guidelines defined in the help center. You should ask this question on the meta site where your concern originated." – ale, Glorfindel, Ward, Nathan Tuggy, gnat
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    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
  • 9
    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
  • 2
  • 4
    This question should not be closed, its completely on-topic! It should simply be moved to meta.stackoverflow.com... Don't you think? – Eric Dec 21 '17 at 15:02
23

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...

  • 2
    I'm seeing a lot of these "code-only" type answers in the review queues lately and I'm starting to feel that if the guy posting the answer can't be bothered to do anything more than post a code snippet, then frankly, he deserves to be upstaged by someone who's taking his initial "spark" and providing a decent explanation. Such an answer absolutely should be accepted over the lazy code snippet answer anyway. – Ortund Jul 19 '17 at 7:22
32

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...

  • 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
12

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.

  • 5
    How are code-only answers worse in this regard than code+explanation answers?   As long as "gimme teh codez" questions get answers, we encourage more low-quality questions.   The remedy to this problem is to close low-quality questions and not answer them. – G-Man Dec 2 '16 at 0:28
5

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.

2

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

  • 3
    Well, that's common sense. – Shadow The Curly Braced 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

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