Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 153 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

Sometimes, when answering SO questions, I am using in my answers the code which strictly speaking is not mine. I mean I have used this code in my applications, and often I have altered it more or less significantly, however I wasn't the author of the code, usually I found it somewhere on the Net.

So the question is: should I mention this fact in my answer? And, if I remember where the code came from, should I just refer the user to this site?

From one side I feel like giving an answer with code in place is much more helpful than just giving a link, however from another side I feel like "stealing" the credit.

EDIT: I am not speaking about the code taken from the open source projects or sites like CodeProject, where it is very clear where the credit goes, I am speaking about code snippets and solutions found on forums or sites like SO.

For example, OP asks how to add some functionality to his/her program, and there is a very specific API for doing so, does it matter that I came across this API on a site that is not Microsoft/Apple/Adobe etc. itself?

share|improve this question
Sometimes, I've answered questions by supplying code that I've written from start to finish and debugged (I'm not John Skeet) without copying/modifying from anywhere, but I don't think these situations are part of what you're asking about. – Agi Hammerthief Apr 10 '14 at 20:26
up vote 13 down vote accepted

I'm not a lawyer either (so Bobby's disclaimer applies to my answer as well), but I'd say it depends on the complexity of the code sample.

If someone asks "How does a for loop work", and you find the following example on the web:

for(int i = 0; i < LIMIT; i++) {
    // do something

by all means, copy it verbatim. It's a textbook example, and it does not contain any significant creative value (I think the legal term is Threshold of Originality).

If the example is slightly more complex and could be considered to be an "original work" by itself, I'd either

  • read it, understand it, and then write my own example, inspired by the other's work or
  • copy it verbatim, providing a link and a reference to the original author (a Quotation) or
  • copy it, modify it to better suit the question, and again provide a link and a reference to the original author (and mention that you modified it).

If the example is significantly complex (= a large piece of code), it's probably not suitable for inclusion in a SO answer anyway, so a link should suffice.

share|improve this answer
1 Booby's disclaimer applies to my answer as well... Yeah...wait, what?! – Time Traveling Bobby Apr 11 '12 at 8:40
+1 for introducing the "Treshold of Originality" concept. – Flot2011 Apr 11 '12 at 8:43
@Bobby: Ugh, sorry for the embarrasing typo. Does not being a native English speaker count as an apology? – Heinzi Apr 11 '12 at 8:50
I'm still trying to decide if I actually like that typo. ;) – Time Traveling Bobby Apr 11 '12 at 8:55
I am totally changing my name to booby's threshold of originality, that would be original. – Tim Post Apr 11 '12 at 10:17
@Bobby - LOL revert to typo! – Adel Apr 11 '12 at 14:45

Disclaimer: I'm not a lawyer. So if I tell you nonsense, you get sued and send to Siberia, it's not my fault!

Everything you post on the Stack Exchange Network is licensed under the "Creative Commons 3.0 - Attribution - Share Alike". So you can not post stuff which would be incompatible with this license or you're not allowed to relicense it.

It all depends on the original license of this code. If it was provided as is in a Forum f.e., I'd assume a very liberal license which only requires attribution (including link) and allows usage for whatever, including quoting and usage on Stack Exchange with attribution.

share|improve this answer
You know, writing the code is not like writing the poetry where you can express yourself in countless ways. Very often there is only one API/technology/SDK whatever for solving a problem, and if I understand this license correctly I should always credit the site where I happen to read about this for the first time. Or I got it wrong, or it is very strange. – Flot2011 Apr 11 '12 at 8:35
@Flot2011: "writing the code is not like writing the poetry where you can express yourself in countless ways". I'm guessing you're not a fan of Perl :) – Merlyn Morgan-Graham Apr 11 '12 at 11:44
@MerlynMorgan-Graham: No real Perl experience, sorry. But perhaps, in the light of your comment, I should try. What is so poetic about Perl though? – Flot2011 Apr 11 '12 at 15:12
@Flot2011: Check out the wiki for the Perl motto, TIMTOWTDI. No worries though, so far I haven't been a fan of the Perl I've seen either. – Merlyn Morgan-Graham Apr 11 '12 at 18:35

In my opinion the real credit for the answer is to that site from which you are picking it, but if the answer too localize like pivot table in mysql, it is too local on various sites ,so there is no need to share link for it.So just give answer in cases like this .

But you have seen any new question whose answer is too unique and you find it on a link and found it rite and have good affert of that posted person then surely you need to provide the link.

share|improve this answer

I don't think there is any harm in giving credit where it is due. In some cases this could be difficult and in other cases the link could be out of date, but at least you've tried.

share|improve this answer

You must log in to answer this question.

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