I have an issue that I detailed with code pastes on http://gist.github.com.

Would it be okay to provide a written description and link to the code pastes, or should I paste them in my question body instead?

5 Answers 5


I would post all (relevant!) code in the question body, for at least two reasons:

  1. People can have a good overview of my problem right away and dive into my code directly rather than repeatedly clicking back and forth.
  2. The code might also include some additional search terms, which is good for future users with a similar problem, or for SEO in general.
  • @smo, glad it helped, cleaning up the comments then. (And note that @Arjan or even @Arj suffices -- see blog.stackoverflow.com/2010/01/new-improved-comments-with-reply)
    – Arjan
    Mar 29, 2010 at 15:53
  • 3
    Relevant is relative. Ideally you should post the smallest, complete set of code that illustrates the issue. If the amount of code is "too large" (forces scroll bars is a good rule of thumb) then I'd resort to posting smaller snippets with a description and link to the larger code sample -- assuming the snippets don't capture the issue. The basic idea, I think, is readability. If your code sample is too large to really be readable in the question, then cut down as much as possible and, if desired, link to the full code elsewhere.
    – tvanfosson
    Mar 29, 2010 at 18:55

Ideally, you should be able to illustrate your problem with the very least possible amount of code. Then I would say that it is best to include the code in-line with your question.

But, if you absolutely cannot be brief in your code samples then, sure, go ahead and link to an external source. But it will greatly decrease the number/quality of responses to your question. Few people will want to go off-site to trudge through large bodies of someone else's code and it becomes more difficult to discuss it back on the Stack Overflow.

  • Thanks, I didn't consider people's reluctance to view code examples off-site :)
    – macek
    Mar 29, 2010 at 15:23
  • 2
    Why not do both -- small snippets + a link to full code if needed?
    – tvanfosson
    Mar 29, 2010 at 18:55

It can work in certain cases.

First, you should do your best to pare your code down to the absolute most relevant bits on SO. Posting giant "wall o' code" questions (or answers for that matter) is discouraged for what I hope are obvious reasons.

Realize that you're asking other people to help you, so if you can help them by making your question as clear, short, and concise as possible, you're more likely to get good answers!

If you feel you absolutely can't pare the code down, and if answerers need to see more of the code, you can provide a [read more..] type of link to a pastebin or pastie or gist or whatever if someone absolutely must see the full, giant code attached to it.


While I always include all the relevant code to answer a question, comments are limited. In that case, a paste service can be an asset, but I would still avoid it if reasonably possible.

My current favorite is codepad.org. It has a clean interface, allows for forks and comments, executes a variety of languages in a sandbox, and will save pastes indefinitely—if you create an account and choose to permanently save.

I find execution especially helpful to demonstrate, confident you didn't make a stupid mistaketrivial error. This is true even for broken code if you want to show the error message. Though I rarely point it out, the confused beginner should be able to discover they can edit and re-execute the paste without having to deal with their local environment.


StackOverflow doesn't provide the functionality that gist.github provides. What's wrong with using gists? Gists provides the ability to revision control the paste -- each poster can make edits and pull from previous versions, fork, etc. This is valuable. Moreover, and impressive -- they don't even need git installed to do it through the web interface.

Maybe SO can license the technology?

  • 2
    SO already does versioning of a sort. Mar 30, 2010 at 4:08

You must log in to answer this question.

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