What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 129 Stack Exchange communities.

How do I respond to a Stack Overflow request for an answer with a complete code sample?

Ideally, I could just upload the HTML file with the styles and JavaScript embedded. Is this possible or appropriate? The editor for posting responses doesn't seem like the right place to place the scripts and HTML.

Also, it is difficult for the amount of code I have. If I can't upload, can I link to another website where I can post the sample? What is the most appropriate way to simply display a completely functioning example in response to a coding question?

share|improve this question

migrated from stackoverflow.com May 13 '12 at 0:03

This question came from our site for professional and enthusiast programmers.

4 Answers 4

up vote 11 down vote accepted

The 'Stack Overflow' way is to narrow down your code to the relevant portions. See Short, Self contained, Correct, Example. Readers typically won't spend a lot of time hunting down the bug in YOUR code, especially if you just upload it and state something along the lines of 'this doesn't work'.

Regarding the method to post that complete example, I have seen and currently use 'helper' sites such as JSFiddle, Ideone, and RegExr. These sites let you host and run code (mostly publicly) and allow you to link to them to share with others. If you REALLY cannot narrow down your problem into a small sample size that can be shared with one of those sites, then typically you should host the code on your own server.

share|improve this answer
    
Actually, the code was completely self-contained and a fully functioning example that answered another person's question. It was just a bit large for stack overflow... jsfiddle seems to be the way to go... –  Reinsbrain May 13 '12 at 16:27

http://www.jsfiddle.net will let you create demos and examples which can be run and forked.

share|improve this answer

I want to add that one of the requirements for posting a question on Stack Overflow is that the question should demonstrate that you've done some research on the topic. You should say what you've tried.

Questions where the question-asker just says "My codez is broke, plz can sumbody hlp me!" are not really the type of questions that we're looking for on this site.

From the Stack Overflow FAQ:

You should only ask practical, answerable questions based on actual problems that you face.

Stack Overflow is for professional and enthusiast programmers, people who write code because they love it. We feel the best Stack Overflow questions have a bit of source code in them, but if your question generally covers …

  • a specific programming problem
  • a software algorithm
  • software tools commonly used by programmers
  • practical, answerable problems that are unique to the programming profession … then you’re in the right place to ask your question!

If you haven't narrowed down your problem to a section of your code, then the community will most likely have some very difficult questions for you regarding your personal dedication to solving the problem. While it is possible to have larger scoped problems, it's important to come with lots of details and be prepared to post them.

The editor for posting responses doesn't seem like the right place to place the scripts and HTML.

If you're referring to comments, then you are absolutely correct. Both questions and answers have an edit link below them where you -- and even other users -- can edit the question or answer to add more detail. This allows you to easily and clearly convey the requested and required information to the community.

Finally, I want to mention that the system was designed precisely for this type of evolution. Whenever you edit your question, it gets bumped back up to the top of the queue on the main page so that others know that your post has been updated. This not only is designed to mold your question into something great, but also it keeps the question visible so that it gets the most possible attention from our community.

share|improve this answer

Respond with extreme prejudice. We're not here to respond to 'plz send me the codez'. Downvote. Vote to close. Post an answer that explains the principle of the thing and firmly sends them off to do their own work.

share|improve this answer

You must log in to answer this question.

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