I wish that StackOverflow used a better clearer license for source code contributions, like the MIT license.
Here is my best attempt at how to copy source code from StackOverflow and abide by the CC BY-SA license. If anyone (especially a lawyer) sees a problem with how I'm doing this, I'd appreciate hearing from you.
Put a comment like the following above the copied code:
// The class below was written by StackOverflow user John Leidegren and is licensed
// under CC BY-SA 3.0 ( http://creativecommons.org/licenses/by-sa/3.0/ ).
Here are the key points that I see from the full text of this license:
- Section 4(a): include the URL to the license.
- Section 4(c)(i): give credit to the original author, by name or pseudonym.
- Section 4(c)(iii): give a URL to the SO source code. (If the source code is in an answer, use the 'share' button on the answer to get a perma-link.)
- Section 3(b): If you make any changes to the source code, add a comment saying "The original code has been modified."
I think that's it, as far as what you have to do.
I would argue that the copied source code is being added to a Collection in your software project, from the viewpoint of this license. That means that the copied source code is under the CC BY-SA license, but the rest of your source code is unaffected.
I think that copied source code also becomes an Adaptation when compiled to machine code, because the license says in Section 1(a) that translations from one language to another (e.g., English to French) count as an Adaptation. So, the one little bit of the executable would be covered by this license. Section 4(b) says that you have to link to the license as part of every "performance" (meaning when the copied code executes) but that's just not possible with most bits of code; you can't display a message "the code that is executing right now is covered by CC BY-SA" in the nanoseconds it takes most code snippets to run! I don't think you have to describe the copied code in credits, if your software has a list of credits, unless you do it for all code snippets from SO, because Section 4(c) says that you only have to make a listing in the credits if you list all contributing authors.