120

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.

9
  • 33
    Most people come to StackOverflow to get answers, not to become better programmers. Sad, but true.
    – Oded
    Dec 4, 2011 at 19:40
  • 7
  • 1
    @Oded "most" ? I doubt that. We want to learn, so we know how to solve solutions in the future. Or at least have a wry of remembering it, or gain trust in the solution. We want to get our code working. But if we have a little or a lot of knowledge alongside it, I think most of us are more comfortable knowing more. I may not learn much, if it's a technology I'm don't have a bad knowledge in. If it is one of my major techs, I can, and will want to understand as much as is reasonable. Sep 3, 2020 at 22:09
  • 1
    @SherylHohman I am afraid Oded is right. Even though the "we" that you are referring to is a large number of people; it compares to nothing when compared to the people who just want their homework done by someone online for free and with no regard whatsoever to what we are trying to achieve here at SO. Sep 4, 2020 at 4:35
  • 1
    Either way, I agree that most answers should contain some explanation ;-). Encouraging explanations skews away from "give me the code" Q & A, whereas seeing a lot of code-only answers gives feedback (subconsciously at least) that free coding-service types of Q's are fine. It also encourages members to answer them with quick code-only answers to gain points, instead of closing inappropriate Q's. When we see many "Comment" quality "answers", code-only, and link-only A's, especially by high rep members (many who are loath to remove/edit very old, low quality A's), it sets a poor example. IMHO. Sep 5, 2020 at 21:38
  • 1
    @Yatin to be quite honest, I don't think anyone on StackOverflow should even bother trying to cater to "the people who just want their homework done by someone online for free and with no regard whatsoever to what we are trying to achieve." That's not the point of this platform. That kind of information is a natural byproduct, but such people are not the ones asking the good questions, they are simply piggy-backing off of genuine questions seeking the right way to do something. It's an information exchange, open to all, curated by the curious, maintained by those who care. Oct 29, 2020 at 14:05
  • 1
    I do come to stackoverflow to find some answers to the stuff I can not manage by myself at the moment, but, if I do not learn in the proccess what I'm doing then? I think every answer should be accompained by a propper explanation because there are many many who come here after an answer but, like me, also to learn. Aug 2, 2021 at 14:05
  • 1
    A very old question but nobody has mentioned that code-only answers can easily be created through plagiarism because they contain no descriptive text, and no links. It's almost impossible to detect plagiarism with code-only answers, unless the plagiarist is lazy/dumb enough to just cut and paste the code, without even tweaking the formatting and variable names.
    – skomisa
    Sep 17, 2021 at 2:53
  • 1
    @skomisa Most of the time, people plagiarizing code are absolutely lazy enough to just cut and paste the code, without even tweaking the formatting and variable names.
    – Ryan M Mod
    Jul 14, 2023 at 1:03

5 Answers 5

50

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
  • 27
    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, 2017 at 7:22
  • Completelly agree Aug 2, 2021 at 14:07
50

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

1
  • 4
    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.
    – Purag
    Dec 4, 2011 at 19:40
23

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.

1
  • 12
    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. Dec 2, 2016 at 0:28
9

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

2
  • 4
    Well, that's common sense. Dec 29, 2015 at 8:11
  • 1
    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, 2015 at 8:17
8

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
  • Except in rare instances, answers without code are lazy, & not considered complete, exact "answers", nor should they. Most times, such replies, suggestions, & hints are appropriately considered comments. As a Comment, such insights are warmly welcomed! Also this isn't an either or situation that your response insinuates. MOST Answers require exact code, as per SO guidelines. Quality answers easily include some sort of explanation, link to documentation, or highlight an important part of A or where the OP went wrong. Without that, it's generally more appropriately left as a Valuable Comment Jul 22, 2020 at 19:48
  • If you don't want to put in extra time, that's fine. Post a quick comment! If the code is a simple one-liner & no explanation necessary, post a comment. Perhaps the Q should be closed anyway. Great, help, the programmer get what they want. Nobody is obligated to spend their time/money here. But Answers should adhere to a higher standard than Comments. To keep the value of SO as a platform high. And to tend toward high quality, useful Answers. Rather than low effort Gaming for points, & haz me the code scenarios. Comments as answers are lazy, & evidently Points are $$, as in cake & eat it too Jul 22, 2020 at 20:02

You must log in to answer this question.

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