14

I asked a question and provided corresponding code inside my question using the tools Stack Overflow provides. Now, someone answered, but I feel like I need to provide additional code specific to his answer.

What is the prefered way to do so?

Does the code styling also work in comments on answers? Or should I provide links to pastebins / gists? Or should I edit my question (risking that my question gets longer and longer)?

Edit: If talking about "additional code", I'm thinking of these use cases:

  1. If I ask a question, I try to post only code, that is relevant to the question. Most often this will be a stripped down version of my original code, because the original code includes way to much irrelevant stuff. However, my attempt to judge what is relevant may be wrong. The problem might be in parts of the code that I didn't post in the original question. So I feel I need to post addtional code!?

  2. As @Sinatr suggested: To show my attempt with answer, which still doesn't work, so that answerer may continue helping me. As I attempt using answers in my code, I change the code, so the questions doesn't contains the latest version anymore. Should I update it? Or leave it as it is? If I leave it as it is, and I get an answers solving the problem with the old code from the question, i'm risking that this solution is not useful for me, because it doesn't fit in my latest version of my code any more...

11
  • 10
    No, in comments you can't format code except for code in backticks. If the answer has missed a critical issue your question is about, edit your question to add that and ping the author about what they missed.
    – rene
    Jul 25, 2018 at 10:11
  • 8
    So pastebins, gists and other external solutions are not really welcome on stackoverflow, am I right?
    – Micha
    Jul 25, 2018 at 10:25
  • 19
    Yes, that is right as they might be removed, go stale, be insanely riddled with ads etc. Users come here to find their answers, not to find a collection of links.
    – rene
    Jul 25, 2018 at 10:27
  • 4
    The site explicitly encourages using somebody else's answer to create your own. Attribution is required, a link to the author's profile and a link to his post. Jul 25, 2018 at 10:30
  • 4
    For what reason is this code? To clarify your question? To improve the answer? To show why answer is wrong? To show your attempt with answer, which still doesn't work, so that answerer may continue helping you?
    – Sinatr
    Jul 25, 2018 at 12:48
  • 2
    If the response has sufficiently answered your original inquiry and you missed details specific to your situation then mark the response as the answer and write a new question. Don't change the original question in such a way that it invalidates the response and don't leave Oh, I forgot to mention ... comments that similarly invalidate a response. You screwed up so man up, accept the answer and write a better question with enough detail.
    – user4039065
    Jul 25, 2018 at 19:53
  • @Jeeped But is it sufficient for the answers to have useful advice if they really don't address the intended problem? Is it really in the spirit of SO to just accept a screw up and move on? Personally, I don't appreciate abandoned questions with pseudo-answers just because someone doesn't want to lose face. That just fills SO with a bunch of useless junk questions. If anything, I think updating the question with sufficient details and then answering yourself is better. If an answer is not known, at least admit the mistake...and maybe even delete the question.
    – C Perkins
    Jul 25, 2018 at 20:37
  • 1
    @CPerkins - The answer attempts to address the problem as originally stated. If it doesn't then DV it. If it does, then it is useful to the community with the original question and should be UV'd and accepted as the answer. Don't change the question because you missed something important.
    – user4039065
    Jul 25, 2018 at 20:49
  • @Jeeped From what I've observed, answers get upvotes if they contain good advice even if they don't contain sufficient or completely relevant info. SO isn't just a repository of nice, useful answers... but instead the questions and answers should correspond to each other. Votes help achieve this, but only the OP really knows if the intended question is answered. If it is not... and the answers don't quite fit the bill, it leads to almost-but-not-quite upvoted answers that litter search results. I just don't agree that "abandon and re-ask" is a useful and productive philosophy.
    – C Perkins
    Jul 25, 2018 at 20:58
  • 1
    @CPerkins - I never suggested 'abandon and re-ask'.
    – user4039065
    Jul 25, 2018 at 21:06
  • +0 for asking on meta instead of "just do it".
    – user202729
    Jul 26, 2018 at 14:07

2 Answers 2

24

Or should I edit my question (risking that my question gets longer and longer)?

Do not edit and scope-creep your original question. If you have additional requirements exposed by the answer, ask a new question. You can include the context of the old question with a link. Be sure to remove any now irrelevant information in the new question.

The problem might be in parts of the code that I didn't post in the original question.

It depends on how drastic your edits are. If it's a small edit, it might be ok to edit the question. Ideally, these kinds of edits would have been caught through clarification comments before anyone answers. For example, if your stripped down code technically has a null reference that doesn't really exist in your actual code, that's probably fine to edit in if an answer tries to fix that non-issue. It's still better to avoid this at the front end of asking the question, but this kind of edit is probably ok.

With more invasive edits, you are effectively asking a different question than before, and you should ask a new question as described above.

To show my attempt with answer, which still doesn't work, so that answerer may continue helping me. As I attempt using answers in my code, I change the code, so the questions doesn't contains the latest version anymore. Should I update it? Or leave it as it is?

Don't update your question in this way. This is what leads to chameleon questions, and the community will rollback your questions to their original state to prevent old answers from being invalidated. Since this answer is probably helpful to the original question, you should consider upvoting it. If you really want to have the same user keep helping, provide them with a link to your new question.

Does the code styling also work in comments on answers? Or should I provide links to pastebins / gists?

Comments are not designed to have robust code support. They are meant for quick, often temporary clarifications. At the point that you require syntax highlighting or have to resort to external links to fit under the maximum character limit, you should consider making a post instead. In this case, a self-answer (as described above) is likely appropriate.

7
  • @ryanyuyu I clarified what I mean by "addtional code" in my question. I would appreciate if you can update your answer accordingly. Thanks!
    – Micha
    Jul 25, 2018 at 15:00
  • Isn't one of Stack Overflow's primary purposes to have great questions with great answers that actually resolve the intended problem? I'm not necessarily disagreeing with all your points, but if one takes your suggestions to a reasonable conclusion, then the intended problem may never actually be resolved (despite potentially useful hints). In attempts to avoid "scope creep" or becoming a "chameleon", the question/answers then becomes what? Should the OP just delete it when OP realizes what it's turning into? I find it annoying to come upon such old limbo questions littering search results.
    – C Perkins
    Jul 25, 2018 at 20:21
  • 1
    @CPerkins The main point is that the answer does resolve the problem as presented in the question. If this is not the intended problem, that's where the asker can ask a new question, hopefully with the intended question and the asked question being the same thing.
    – ryanyuyu
    Jul 25, 2018 at 20:41
  • @ryanyuyu The OP never stated that the "answer" actually answered the question... even as presented in the original question. Many attempted answers don't quite fit the bill, even if they are worded nice and have useful advice. Just because it is labeled an "answer" doesn't imply that it actually resolved either the original or the intended question. You didn't actually address my concern about the old, unresolved limbo questions that linger. Sorry, but the appropriate answer can't just be to "abandon and re-ask".
    – C Perkins
    Jul 25, 2018 at 20:52
  • @CPerkins in the "answer was not helpful" category, see klutt's answer. That's the situation you're dealing with at that point. And if you don't like the "abandon and re-ask", how about close, delete, and re-ask? If the question is unclear, it should be closed as such. My assumption based on the OP's question is that the iterative process of the comments was because one problem was solved, which revealed another one. If this is not the case, downvote the unhelpful answer/close and edit the question to be more clear.
    – ryanyuyu
    Jul 25, 2018 at 21:46
  • @CPerkins It's not the answerer's fault if the OP doesn't manage to ask the question that they really need help with. Certainly, answerers should assist the OP with their actual problem, and part of that assistance may involve helping the OP to clarify the question. Ideally, that should be done before anyone starts writing answers. It's fine to improve the clarity of the question after it's already received valid answers, but it's not acceptable to make changes that can invalidate those answers, or reduce their relevance.
    – PM 2Ring
    Jul 27, 2018 at 11:32
  • 1
    @CPerkins OTOH, it often happens that the question isn't completely clear but some people start guessing what the OP really means and submitting answers which may become irrelevant when the OP does clarify their question, but such people are taking a calculated risk, and should be aware of the possible consequences. ;) The OP is under no obligation regarding such FGITW answers.
    – PM 2Ring
    Jul 27, 2018 at 11:33
11

I think you are starting in the wrong end.

Your problems is 99% due to a lack of a Minimal, Complete, and Verifiable example (mcve)

If I ask a question, I try to post only code, that is relevant to the question. Most often this will be a stripped down version of my original code, because the original code includes way to much irrelevant stuff. However, my attempt to judge what is relevant may be wrong. The problem might be in parts of the code that I didn't post in the original question. So I feel I need to post addtional code!?

When you are having a problem, strip away as much as possible. Make the code as small as possible, while still reproducing the problem. When you have stripped down your >4k lines of code to just a function or two and the boilerplate needed to run it with input that will cause the precise problem you described, then you will have a mcve.

You should not ask a question before you have done this. And the chance is actually pretty good that when you have done it, the solution will be obvious to you, to it is not even necessary to post a question. Of course, if you find the Q and A interesting enough, you can post it anyway and answer it yourself.

To show my attempt with answer, which still doesn't work, so that answerer may continue helping me. As I attempt using answers in my code, I change the code, so the questions doesn't contains the latest version anymore. Should I update it? Or leave it as it is? If I leave it as it is, and I get an answers solving the problem with the old code from the question, i'm risking that this solution is not useful for me, because it doesn't fit in my latest version of my code any more...

No, you should not update your code incrementally when people answer. Only correct small typos and such, but in general, this situation should never occur. When you post a question, first create a mcve as stated above, and then copy paste the code to make 100% sure that the code we see reproduces your problem.

If needed, post a new question instead, but if you need to do this more than once on a single problem or that you have to do it on more than at maximum every tenth problem or so, then it is a very good indication that you need to spend more time with your questions before posting them.

Short summarize

C Perkins summarized my answer pretty good in a comment:

Don't use Stack Overflow as a debugging platform where others end up doing the debugging for you. I totally agree with the MCVE intention, but what's often lost in that suggestion is that to get to an MCVE, one needs go through some sort of valid iterative debugging process. (Regrettably, many suggestions that point toward debugging skills are interpreted offensively whereas suggesting an MCVE is abstract enough that it's often more acceptable.)

3
  • 5
    If I may summarize what klutt is saying: Don't use Stack Overflow as a debugging platform where others end up doing the debugging for you. I totally agree with the MCVE intention, but what's often lost in that suggestion is that to get to an MCVE, one needs go through some sort of valid iterative debugging process. (Regrettably, many suggestions that point toward debugging skills are interpreted offensively whereas suggesting an MCVE is abstract enough that it's often more acceptable.)
    – C Perkins
    Jul 25, 2018 at 20:06
  • 1
    @CPerkins Well said. I included that in the answer.
    – klutt
    Jul 25, 2018 at 21:56
  • 1
    I'm still wondering what is the remaining 1% cause
    – Pac0
    Jul 27, 2018 at 11:37

You must log in to answer this question.

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