This question already has an answer here:

I have a simple query:

I have been working on some interesting jQuery stuff lately and I have created an interesting piece of code. And I wanted to post it in SO, so that if any OP have a similar query, they have the code ready and the issue fixed in a jiffy.

But I really don't know where to put the code in SO. Is there any appropriate place to do so? or we can't do this in SO and I need to post in some blog or something?

Looking forward to your positive responses!

marked as duplicate by gnat, Time Traveling Bobby, hims056, Toon Krijthe, Grant Thomas Apr 8 '13 at 12:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 6
    SO is a question and answer site, not a code hosting site. For the record, I should mention that your question here doesn't even have a proper title. If you can't think of a good title for a question, then I suspect you won't be able to write a good question that whatever code you have written would answer. – BoltClock's a Unicorn Apr 8 '13 at 11:37
  • 3
    Just to warn you, if you post a self-answered question, make sure that the question can stand on its own. Non-questions that serve as a poor excuse for an answer - even if that answer itself is good, insightful, and interesting - are generally poorly received. – Daniel Fischer Apr 8 '13 at 11:38
  • @gnat - Not really a duplicate. The emphasis here is on sharing code, not self-answering. – Oded Apr 8 '13 at 11:51
  • 2
    @Oded please take a look at the text of suggested dupe: "I might want to answer my own question because... I have a folder with lists of code snippets for things I always forget or get wrong..." - to me that's as much about sharing code as it gets, isn't it? – gnat Apr 8 '13 at 12:04

If your code is answering a specific problem, you can formulate a question that it answers.

This is fine. And we have specific provisions for asking a question that you can directly answer.

However, do make sure the question follows the FAQ guidelines.

In general - Stack Overflow is not a code-sharing site. It is a Question and Answer site. Keep that in mind.


You don't, generally. In circumstances it is acceptable to post a question for the sole purpose of answering it, but doing so should not be taken lightly, in my opinion.

For instance, if it's a common problem and there's demand, then there could be a call for it. You have to be careful not to duplicate content though, even (or particularly) questions; if it is a common problem that people often need an answer to then the chances are your question already exists and you only need find it in order to answer.

An example of posting a question and answer might be to give a definitive, canonical pair. For instance, a great many people ask about NullReferenceExceptions in .NET, each in their own way. often not even mentioning the exception name - the answer is always the same, just a variation; now, it could make sense to create a pair to explain this thoroughly, that anyone with the same problem will be able to find using terminology the compiler gave them, and understand that the operation is the same, half of 5 is the same thing as half of 5 dollars or half of 5 pounds.

John Saunders did give such a pair.


You can ask a question and on the bottom of the "ask question" page there is an "answer your own question" tick-box, which you can use share knowledge on Stack Overflow.

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