I was wondering about the copyright of code snippets from answers. Let's say you ask a question and the solution consists of ten lines of code, which are given in an answer. Are there any restrictions about the use of that code?

It seems that the content of this page is under the creative commons license. So does one have to attribute the author if code is used in an open source project? Can it be legally used in closed source projects at all?

I guess ten lines of code are not really problematic, but is there a critical number of lines?

Return to FAQ index

share|improve this question
2  
See my answer for a way to work around this. –  waffles May 22 '09 at 7:53
add comment

12 Answers

up vote 17 down vote accepted

Anything that you post to Stack Overflow will be under the terms of the Creative Commons license. You can find more information by looking at the bottom right of the page and clicking the cc-wiki link.

As far as more specific legal issues, you should probably consult an attorney.

share|improve this answer
13  
So basically if I paste a 10-line snippet of code from stackoverflow into my project, I must now distribute my project onder CC by-sa as well? –  davr Sep 24 '08 at 17:54
    
If you include a code snippet from another source, you can't arbitrarily for that content to Creative Commons ... it stays under it's original license until the copyright holder says otherwise. –  Steve Moyer Sep 24 '08 at 17:55
13  
Nothing here changes who owned the code before it was posted. If the poster didn't have the right to post it (because of his company's IP provisions, or because it was taken from elsewhere) the CC license doesn't stop the original owner from claiming infringement against someone who downloads. –  Will M Sep 24 '08 at 18:03
    
@Davr - If you plan on releasing the code under a license that would be incompatible with the creative commons license, I wouldn't post it to StackOverflow. I would imagine that this wouldn't be a problem for most FOSS licenses. And if this is proprietary code, I wouldn't post it to begin with. :) –  Jason Baker Sep 24 '08 at 18:24
20  
No...I'm talking about the other way around. I ask "How do I do Foo?", then someone answers with some source code, presumably licensed under CC by-sa. What happens when I take that source code, and add it to my non-opensource application? –  davr Sep 24 '08 at 20:28
1  
I modified a code I found on stackoverflow and add it to my program (which I intend to release under GPL). I mentioned in comments the person who wrote it and added the url to the topic on stackoverflow where I found it. Do I need to do anything else? –  Adinan Nov 10 '13 at 15:43
    
@Jason: Realizing this wasn't Davr's question, I think your earlier comment missed something. IANAL, but afaict you can post a portion of closed source to SO and "dual license" (since it's all yours). If I have closed foo, sublicense foo to you, your posting foo to SO doesn't stop me from continuing to treat foo-superset as otherwise closed. Same if that "sublicensee" is myself. You can use foo on SO under CC, and I can use foo-superset as closed without suing myself. ;^) See MySql and dual licensing. –  ruffin Nov 30 '13 at 17:12
add comment

This is a software licensing nightmare. If you paste in snippets in your answer that are in an incompatible license to cc-wiki, you are violating the terms of SO. I would imagine there are probably thousands of examples of such violations.

In addition to that major issue, I personally like to choose how to license my work. I am happy for all the text to be the viral cc-wiki. But am very unhappy to have my little code samples or classes under cc-wiki.

To combat this issue I just added this snippet to my profile on SO

All original source snippets I post on stackoverflow are dedicated to the public domain. Do with them as you see fit.

All those who are against the viral nature of the source samples should explicitly say what license their samples are in.

Another option is to post any larger snippets to sites like gist and have a license in the header of the file.

share|improve this answer
9  
The "Public Domain" is not a license. Licenses are a type of contracts. The Public Domain is the set of works that fall outside of copyright, for whatever reason (eg too old, not creative, explicitly put there). Even so, your intent is clear enough to put your code in it. –  MSalters May 22 '09 at 8:10
    
thanks, fixed it up –  waffles May 22 '09 at 13:45
10  
"Public domain" does not exist in many countries, so if you want everybody to be able to use your code snippets without worries, consider using CC0 (if you like Creative Commons licences), WTFPL, Unlicence, or the like. –  Chris Jester-Young Nov 30 '11 at 21:08
    
This is much more helpful than the accepted answer, but for such a re-dedication to be meaningful, it really needs to be a license in itself (as @ChrisJester-Young noted). The license closest to the public domain is the Unlicense. –  bukzor Mar 10 at 18:25
add comment

If you are talking about taking code from Stack Overflow for use in your work, I would be very careful. Even if it is the opinion of the people here that posts to Stack Overflow are covered by Creative Commons, you will need to be able to prove that you got the code from here.

A Short Story To Illustrate:

  • Someone else decides the code is a good solution for a problem they are facing, and decides to copy it into their open source GnuFizzBuzz project, covered by the GPL.
  • Five years from now, someone is doing an open source audit on your code (maybe you are selling to a nervous customer, or your company is going public).
  • The open source audit finds the snippet of code you got from Stack Overflow, and recognizes it as originating in GnuFizzBuzz.
  • You are now stuck explaining how/why you have GPL code mixed into your commercial product, or proving that the code was actually from Stack Overflow. Can you prove that the person posting the code to Stack Overflow owned it to begin with (maybe they actually copied it from GnuFizzBuzz to begin wih).

It may sound unlikely, but I have seen this exact situation with my own eyes. The safe thing to do is to regard any code snippets you find as explanations of how something could work. Read, understand, and write a solution based on your understanding. Don't ever cut/paste code you found on the Internet if you are working on a commercial product.

share|improve this answer
5  
...so, if including code from SO, include the URL in a comment. –  msh210 Dec 19 '11 at 21:30
1  
If you rely on specific code (and to which copyright applies), contact the author. CC-WIKI is not a software license and you want to have usage terms more clear than the CC-WIKI license is able to specify it. –  hakre Jan 30 '12 at 15:05
    
In this answer (by Jeff Atwood actually) it's written that "a snippet of code falls under excerpt category and thus should be free to use under fair use" — but when is a snippet too long to be a snippet? –  KajMagnus Feb 22 '13 at 11:00
1  
@KajMagnus: That's a legal judgement, and it's wrong. Fair use doctrine does not apply to embedding excerpts of copyrighted work into source code. –  bukzor Mar 10 at 18:44
add comment

This has been discussed on UserVoice already. Jeff closed the request with this response:

I would hope that people are not posting giant blocks of code at SO, making it more of a quote / fair use type situation.

For commercial work, you should see your company lawyer before using any code from SO.

share|improve this answer
1  
Thanks for the uservoice reference, seems that this is as clear as it gets. –  nikow Sep 30 '08 at 15:36
7  
Its clear, but as the owner of a copyright you have the right to license your work under whichever license you see fit. (in addition to the cc-wiki on this site) I attached a disclaimer to my profile saying that I am giving away my snippets. I hope others follow suite –  waffles May 22 '09 at 7:54
    
@sambo99 That is a great idea. –  Sinan Ünür May 22 '09 at 20:46
    
The only trouble is that there are legislations which unfortunately do not have a concept of "fair use". But I also agree that such small snippets will probably cause no problem, since all implementations of "standard" problems tend to look alike. I also want to hint to this CC FAQ about the use of CC licenses for software. –  quazgar May 23 '13 at 11:26
    
Considering the Code Review site, where long/giant blocks of code is the norm, I'd say that Jeff's answer is quite outdated. –  Simon André Forsberg Dec 19 '13 at 1:45
add comment

The two relevant questions are (1) what jurisdiction applies and (2) assuming US or sufficiently similar, is the snippet large and original enough to be covered under copyright law. Line counts are not magical; no amount of the following code would be covered:

switch(int i) {
  case 0: return "zero";
  case 1: return "one";
  case 2: return "two";
  //...

But if you can put that same functionality into 5 lines of code for i < 1<<32, those 5 lines will quite likely be considered sufficiently original and complex to be covered.

share|improve this answer
add comment

I am not a lawyer, but I think if you do a direct cut and paste of the code then you are going to have to look at what the site's cc-wiki gives you permission to do. Personally, I think that if you read the code, understand the code, and then use that knowledge to write you own take on what the code is doing you might skirt by the copyright issue as you aren't doing a cut and paste of the code.

However, it is worth noting that you do have to be aware that there might be a patent on the code in which case you have to be aware of those issues. That is an area were you are starting to look at having a lawyer render an option on it - if you work at a company then someone in the legal department might be able to give you an answer on the quesiton.

share|improve this answer
add comment

In the US, the Copyright is owned by whomever posted the solution. That said, I really doubt anyone would post anything on this site with the intent of punishing people for using the code. If I didn't intend to make the code freely usable, I wouldn't post it, which is why I'm really careful about what I post and I try to make sure that it's been sanitized for anything I wouldn't want to give up.

share|improve this answer
8  
It's owned by whoever owned it before it was posted - that may the poster, it may be the poster's employer or, for example, it may be the person or company that poster stole it from. –  Will M Sep 24 '08 at 17:59
add comment

I've been careful to only use code snippets that do not reflect the core intellectual property of my company. I think there are definitely instances where I could divulge trade secrets in less than ten lines of code.

In any case, in instances where you're sharing code snippits from an open source project, it would be great to denote what license included code uses and maybe default to something generic like Creative Commons.

share|improve this answer
add comment

When someone posts code in here, he intends to give his code to everyone visiting the question. IANAL, but doesn't this automatically put the code into the public domain? (some form of duck-typing, in our terms)

share|improve this answer
2  
While that technically is a matter for judges to decide, the Creative Commons reference on each page stronlgy suggests that it is not (yet) Public Domain. –  MSalters May 22 '09 at 8:07
1  
IANAL, but I don't think you can implicitly disclaim copyright. The legal system does recognize duck-typing for some things, but not everything. –  David Thornley Oct 15 '09 at 21:36
add comment

Only a lawyer can answer this question. But, very relevant are fair use and whether a small snippet of code is copyrightable.

Also, the implicit license it was posted under is relevant when asking a lawyer their opinionion. A lawyer might say that it would be difficult for someone to reasonably argue that their copyright was violated when code they post in response to a question is used in any way. Legal concepts such as promissory estoppel might come into play. It would also be interesting to see if reputation points could be deemed "consideration" under the law.

Patent issues are a much bigger risk, because the patent law is so nonsensical and keeps getting worse. Software patents are very dangerous and have already caused great damage to the software industry and free software.

Also, export restrictions (e.g. ITAR) are very dangerous, although some important precedents protecting source code as speech have been set. There was a time when simply having hooks to process data before sending it on its way was restricted as a munition in the US.

share|improve this answer
2  
There is no implicit license. There's an explicit one - CC-BY-SA. –  David Thornley Oct 15 '09 at 21:37
add comment

The cc licence link states that this page is attribution/share-alike.
That suggests (to me, IANAL) you CANNOT use a code sample in your commercial work.

The original poster of course retains copyright and so you could always ask them for permission.

share|improve this answer
add comment

You don't have to worry - why would you be worried, why would you release stress hormones to the the organism?

There is a cure - open-sourcing your code under Creative Commons licence: enter image description here

Today I wrote a post about it: http://www.iamthespecialist.com/2014/01/stack-overflow-licensing-virus.html

  • My feeling: CC by-sa 3.0 was introduced to reduce legal burden.
  • My feeling: The are other, more applicable licenses to code.
  • My feeling: Dual-licensing for various bits & bobs (maybe?)

(I wonder how my point of view will evolve in 5 years)

share|improve this answer
add comment

You must log in to answer this question.

protected by Robert Harvey Aug 21 '13 at 2:20

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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