36

I'm working on an OSS project and often ask questions about how to fix or improve my code.

I was wondering to what extent contributions made by Stack Overflow should be recorded.

Should answerers be added to the contributor list?


Extremely relevant

4
  • 1
    Related on Programmers: How and when had the CC BY license become GNU GPL-compatible? Commented Dec 6, 2015 at 21:00
  • 2
    Hmmm... They're also the concept of "fair use" and whether snippets of code are even copyrightable to begin with. Open Source SE may be a good resource :)
    – Zizouz212
    Commented Dec 6, 2015 at 22:47
  • 1
    At least in some jurisdictions, computer programs are exempt from the creativity bar of copyright. IOW: print("Hello World"); is copyrighted. Commented Dec 9, 2015 at 2:24
  • 1
    @JörgWMittag Tell that to Oracle. :)
    – erip
    Commented Dec 9, 2015 at 2:25

2 Answers 2

27

If you rewrite the code using ideas a question/answer gave you, then it's your work, and you can do whatever you want with it.


Update for answers written on/after March 1st, 2016 (Preliminary, work in progress):

Content on StackExchange that is written on/after March 1st, 2016 is now under an MIT license with an additional right for you:

You don’t have to include the full MIT License in your code base. Contributors agree to give code users permission to ignore the MIT License’s notice preservation requirement, as long as users give reasonable attribution upon request of the copyright holder (or Stack Exchange on behalf of the contributor). This optional exception to the MIT License will live in our terms of service.

So

To future-proof your work, [Stack Exchange] recommend[s] you do one of these 2 things, or both:

A) Add a comment to your code that links back to the post where you found it
B) Comply with the MIT as it’s typically used, by including the full license text in your source

If your project is open source with an MIT license, a compatible license (such as the GPL), a GPL compatible license

Confused by this? Just treat the code you find in Stackoverflow as if it's licensed as an MIT License (without the additional right).


Before March 1st, 2016:

You must give attribution, under the terms of the CC BY-SA 3.0 License

You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

So putting them in a contributor file might count as a "way that suggests the licensor endorses you or your use," which isn't true - you should probably write something like this:

This licensing text was created by penne12 on StackOverflow under a CC BY-SA 3.0 License, but he doesn't endorse this project in any way. You can see the answers from which I used code here:

Or something like that. You can also put a link in your source code, which might help to keep your contributor file for those actually contributing (with PRs and new features) to your project:

// Function from penne12 on Stackoverflow (https://meta.stackoverflow.com/a/311848/3144928) under a CC BY-SA 3.0 License
function doComplexStuff(number){
    console.log("Doing Super Complex Stuff")
    if(typeof number !== "number"){
        console.error("That's not a number");
        return NaN;
    } else if(number == 42) {
        return "correct";
    } else if(number == 3.14) {
        return "yum";
    } else {
       return "maybe"
    }
}

Remember, this is only if you publish the code - if it's never given to anyone (server side code, obfuscated code, compiled code, etc), you shouldn't have to do this. You can use the code for commercial purposes.

Just make sure you

  1. Mention the code is under the CC BY-SA 3.0 License (unless your codebase is licensed under the GPL, or a GPL-compatable license such as the MIT License)
  2. Mention the user you got it from (include a link)

If you are putting code written by someone else that's GLP licensed on your answer/question, you normally can't use it without written permission, but there's another question about this.

Help page


I'm not a lawyer - and I'm not your lawyer either. This answer is based off of US copyright law. Reading this doesn't create any form of legal bond. The answer is provided as-is - I'm not responsible for your use.

11
  • IANAL but I think you need to include the text or URL of the Creative Commons license in all cases, regardless of other licenses. Also, your comment about taking GPL code seems misleading -- if you're getting code from SO you can use it under CC terms (unintended for software as they might be) and ignore any GPL terms, if you want. The question you linked is about putting GPL code on Stack Overflow, not taking it from Stack Overflow. Commented Dec 6, 2015 at 22:35
  • @JeremyBanks Phrased that wrong - here's creative common's compatible licenses and the gpl compatibility with cc by-sa
    – Ben Aubin
    Commented Dec 6, 2015 at 22:42
  • 1
    If you read this text you agree to give me a million dollars. I would not expect this to hold in court, just like your last sentence wouldn't.
    – nwp
    Commented Dec 9, 2015 at 11:42
  • 2
    @nwp Damn it. What's your bank account, anyway?
    – 5gon12eder
    Commented Dec 9, 2015 at 14:52
  • @nwp changed the text to "this answer is provided as-is" - that'll probably hold up better... but yeah, I don't have a million dollars. It a millionth of a dollar ok?
    – Ben Aubin
    Commented Dec 9, 2015 at 14:58
  • Is not "now" under MIT license... heck they aren't sure that that would be the license by 1 jan.
    – Braiam
    Commented Dec 17, 2015 at 1:38
  • Probably should change that then - sorry.
    – Ben Aubin
    Commented Dec 17, 2015 at 1:39
  • Update: They're now planning to change the licensing terms on February 1, 2016.
    – jkdev
    Commented Dec 23, 2015 at 4:06
  • @jkdev Thanks for letting me know!
    – Ben Aubin
    Commented Dec 23, 2015 at 4:57
  • Update: They're now planning to change the licensing terms on March 1, 2016.
    – erip
    Commented Jan 15, 2016 at 16:13
  • 1
    Update: They're now planning to change the licensing terms sometime in the future. Commented Jan 17, 2016 at 0:11
12

I don't think that this is so much a legal issue; it's a moral one. Code can be copyrighted but ideas can't. If you copy an answer verbatim into your code base, then yes, you have to obey the Creative Common license. But if you're writing a project using this copy & paste approach, you'll likely get into bigger troubles than licensing issues anyway. If instead, you do your homework and boil down your questions to isolated minimal examples, you will need to transform the answer back into the context of your project. While doing so, you re-write the concept you've learned from the answer in your own “words” and subsequently become the author of it. This doesn't mean that you shouldn't give credit to the person who taught you the concept. I think a simple comment in the source code will usually be appropriate. Something along the lines of “the frobnification logic is based on an idea of J Random Hacker posted in this Stack Overflow thread [link]” or “this works around a bug in Clang as explained by somebody here [link]”. You don't have to do this in a legal sense but if you feel it is the right thing to do, it probably is. Apart from that, such a comment also has value on its own because future readers of your code may look at the answer on Stack Overflow and – unless it's merely a code dump – perhaps learn something. Don't list anybody in an “authors” file unless the person told you they want to be listed. Being listed there implies some kind of endorsement or mental affiliation with the project which you cannot assume from a person who simply answered your Stack Overflow question without even knowing about your project.

3
  • 2
    What you say applies in some cases, but there are reasonable cases for copy-pasting code from Stack Overflow. The legal consequences of that really do need to be addressed. It's not just people are writing their entire project using a copy-paste approach. If someone's already provided an implementation of some generic utility function, using it verbatim can be reasonable, particularly if you include a link so future devs can see the context and the community's comments on it. This is more like using an open-source library function than anything else. Commented Dec 6, 2015 at 22:44
  • 2
    Like @JeremyBanks says, it's perfectly reasonable to use well-defined isolated chunks of code as-is. For example, recently I dropped an ISO 8601-parsing function into a script I was writing, and had to do nothing other than changing code to call that instead of Date.parse. Cargo cult programming is certainly a terrible idea, but the best SO answers don't allow that very well anyway. Commented Dec 6, 2015 at 22:47
  • 3
    If you are using an idea from somewhere, it's in your own interest to make a comment about that anyway, so you (or other readers) can later find it again to (re-)read it. Most likely, there's a good explanation there too. Commented Dec 7, 2015 at 0:35

You must log in to answer this question.

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