37

If I have a question about a section of code in a library open sourced under a BSD style license is it alright to copy/paste the section of code relevant to my question onto Stack Overflow?

Almost all BSD licenses say something along the lines of

Redistributions of source code must retain the above copyright notice

If I paste the relevant section of code do I need to copy the license over as well?

17
  • 4
  • good question, to urge on the safe side, I would recommend doing so and making sure its noted that you're quoting the copyright to make sure its not edited out Commented Apr 17, 2018 at 8:26
  • 3
    In theory, yes, you can dual license BSD with CC-BY-SA 3.0 by including the copyright notice in the question itself. In practice, that will magnet downvotes, close votes and delete votes by the community.
    – Cœur
    Commented Apr 17, 2018 at 12:59
  • 2
    @Cœur "In practice, that will magnet downvotes, close votes and delete votes by the community" -- (1) Is that really supposed to happen, though? (2) Do you happen to have any example of a Q&A in which that happened? I'm now curious to see how that has played out.
    – duplode
    Commented Apr 17, 2018 at 13:48
  • 2
    @Cœur That is a question about the license itself, though, and therefore off-topic. (I can see how, in a "normal" question, the license text might be seen as noise, but downvoting and voting to close don't seem like appropriate reactions to that.)
    – duplode
    Commented Apr 17, 2018 at 13:55
  • 3
    @duplode oh well, you may be correct about not always attracting downvotes, as I found some upvoted ones by googling: 41762832, 44486169, 36902923, 43717798, 47126878, 34034157, 28397536, 4968732, 27679851
    – Cœur
    Commented Apr 17, 2018 at 14:04
  • 1
    This is also probably related to the question of embedding copyrighted images.
    – Jeremy
    Commented Apr 17, 2018 at 15:07
  • 1
    To be clear, are you asking about a question where the nature of the copied code would be beyond what fair use would allow?
    – user743382
    Commented Apr 17, 2018 at 18:12
  • 2
    @hvd Does fair use apply to copyrighted code? If so, how much code can be copied under fair use? Commented Apr 17, 2018 at 18:14
  • 4
    @IncreasinglyIdiotic Fair use is an exception to copyright law. It doesn't apply to anything other than copyrighted material. "How much" is the wrong question, because the exact same amount can be acceptable in one instance but unacceptable in another. It's complicated.
    – user743382
    Commented Apr 17, 2018 at 18:27
  • 1
    This is, at best, complex. There are issues of both copyright and potential plagiarism. The issues around copyright vary significantly from country to country. In the USA, this will most likely be a "Fair Use" issue/argument, which just by itself is complex, and can, ultimately, only be resolved in court. Plagiarism is a bit more clear-cut. It's defined by the community as passing-off something which you did not create as your own creation, either explicitly or implicitly. Plagiarism applies if they don't say, in some way, that the code isn't theirs.
    – Makyen Mod
    Commented Apr 17, 2018 at 19:00
  • 2
    In my view (IANAL) this is a textbook example of fair use, especially if the fragment you are copying is small in relation to the whole. One of the key principles of fair use is that you are not depriving the copyright owner of any opportunities to exploit their rights, and that is certainly the case here. Commented Apr 17, 2018 at 20:23
  • is redistributing the text of the code the same as redistributing the code? For example, if I print some code in a book about good coding techniques, that code isn't able to be executed (because it's in a book!) and is not being printed for the purpose of being executed (because it's being used for illustrative purposes). I understand that someone could transcribe the example and execute it, but was that because I distributed that code? It seems like any code printed in said book should be under some umbrella clause like "not to be used in distributed code without permission".
    – Anthony
    Commented Apr 18, 2018 at 1:23
  • 2
    Also, would this be a potential feature for SO, where you could cite a general license, which would link to the full license text, rather than bulking up each question with a full license preamble?
    – Anthony
    Commented Apr 18, 2018 at 1:26
  • @Anthony "is redistributing the text of the code the same as redistributing the code?" -- IANAL, but I would be extremely surprised if it wasn't. It seems transcribing the code into a text file should make as little difference in this context as extracting it from a tarball would.
    – duplode
    Commented Apr 18, 2018 at 1:46

4 Answers 4

13

BSD is a permissive license. It's only stipulation is that you respect the copyright holder's copyright notice, and that you include the disclaimers. So the intent of the BSD license is to be as unrestrictive as possible. Choosing it means you choose to make your code public for any purpose (short of outright theft), and that you basically understand that your code is going to be copied and used everywhere, which is kind of the whole point.

But the license nevertheless does say that you must include the copyright notice with your redistribution. So what should you do? Well, you should probably do what the license says. However...

By way of illustration, I'm going to pick on Dapper for a moment, Sam Saffron's1 brilliant object-relational mapper that drives the Stack Exchange network. I willingly give Sam permission to slap me upside the head if I get this completely wrong, but here goes.

The heart of Dapper is the SqlMapper class. Everything else in Dapper is window dressing and additional features. Within the SqlMapper class is a bit of code that looks like this:

private static readonly System.Collections.Concurrent.ConcurrentDictionary<Identity, CacheInfo> _queryCache = new System.Collections.Concurrent.ConcurrentDictionary<Identity, CacheInfo>();

private static void SetQueryCache(Identity key, CacheInfo value)
{
    if (Interlocked.Increment(ref collect) == COLLECT_PER_ITEMS)
    {
        CollectCacheGarbage();
    }
    _queryCache[key] = value;
}

What is this _queryCache they speak of? What is its purpose? Is there really a custom, reference-counting garbage collector in there?

Now of course, I could just link to the SqlMapper class directly, which I will do anyway because I'm a nice person and I want to be polite and respect Sam's work. But isn't it also nice that I included the specific bit of code that I was talking about, and not "look at lines 62 to 70 in the file I linked?"

Should I include a copy of the license in this post, or at least the preamble? (It's the Apache 2 license, so it works a little differently) Probably. Am I going to?

No. Here's why:

  • If it were my work, I wouldn't expect people to have to include the entire BSD license to point out a few lines of my code in a Stack Overflow question.

  • Nor would I expect people to ask me for permission. It costs you and me more time and effort to ask and answer that question than it does for me simply to assume you're acting in good faith.

Of course, if you decide to copy the entire SqlMapper class into a blog post without so much as crediting Sam or linking back to his Github repository, I think he would be at least a little bit put off by that.

The purpose of redistribution2 clauses is that, if you're going to write your own program and copy my work into it, then you ought to do the decent human-being thing and include my copyright notice so that I can at least get a bit of recognition instead of claiming all of the glory for yourself, and to preserve the disclaimer protections.

1Sam Saffron is the original author, AFAIK. There are several contributors, including Marc Gravell, Nick Craver, and invalid-email-address, to name just a few.

2The BSD doesn't specifically define the term redistribution, but I think it's generally fair to say that redistribution means "incorporating all or a substantial part of a library or its source code into a new program, thus creating a derived work, and then distributing that derived work to others."

5
  • I doubt the few lines of code you posted have enough creative merit to be granted a copyright. Commented Apr 19, 2018 at 10:08
  • 2
    @Goyo: They're already part of a copyrighted work. Commented Apr 19, 2018 at 14:39
  • Yes, but they are not "a substantial part" of it, using your own words. That is also the wording in the MIT License: "substantial portions of the Software". The FSF says that "small changes" can be accepted without a copyright disclaimer or a copyright assignment". Not every tiny bit of a copyrighted work is itself copyrighted. Where to set the bar is unclear, tough. It varies across countries and even across courts in the same country. Commented Apr 19, 2018 at 19:59
  • 1
    @Goyo: I'm sorry, but I don't agree with your legal assessment. Every part, large or small, of a copyrighted work remains copyrighted. What you're referring to are "subsequent consequences or actions," like violation of copyright and fair use. They don't affect the original copyright in any way. Software licenses dictate licensing terms, not copyright terms. Commented Apr 19, 2018 at 20:05
  • Don't be sorry, IANAL. I just don't get why whether a small code snippet comes from a larger work or not should be relevant when taken in isolation. But there are so many things I don't get about copyright. Commented Apr 19, 2018 at 21:57
11

If you redistribute BSD-licensed code and do not follow the terms of the BSD license (i.e., reproduce the required notice(s)), then your use is not permitted under the author's BSD license grant. This is generally true of any copyrighted material under any license, however permissive or restrictive: if you don't comply with the requirements of the copyright holder's license grant, then you don't have permission to do whatever the license grant permits.

In the United States, you may be able to defend your otherwise-unauthorized use as fair use. In legal terms, your unauthorized use constitutes prima facie ("at first sight") infringement, but you affirmatively defend your use as "fair" to a court of law according to the four fair use factors.

Fair use factors are notoriously nebulous and their applicability varies from case to case, but if you are using a small amount of previously-published code for the purpose of learning how it works, you have a pretty good case. You won't know for sure, of course, until the copyright holder initiates a lawsuit against you, the suit goes to trial, and a judge or jury passes judgement about the correctness of your fair use defense.

In interpersonal terms, the idea of the author of a BSD-licensed program taking or threatening legal action over educational use of their code seems absolutely absurd.

In ethical terms, you can avoid the risk of plagiarism by identifying the source of the copyrighted material, so people do not wrongly credit you as the author.

0
-6

Of course you should include the copyright notice. Since this is a web page, you do that by providing a link to the copyright notice. Like this:

//trivial code

(BSD Licence)

Since the BSD licence includes

Copyright <YEAR> <COPYRIGHT HOLDER>

you must link to the actual licence, not the proforma. And it gives you the copyright notice, which is the BSD requirement.

If that was difficult, you might worry about is it necessary. Since it adds just one link to your question, you should do it even for trivial amounts of code.

3
  • 3
    No, a link is not enough for BSD license, because it uses the wording must retain.
    – Cœur
    Commented Apr 19, 2018 at 9:53
  • That is an interesting interpretation of "must retain". Do you have any citations that justify your belief that downloadable content is not "retained"?
    – david
    Commented Apr 20, 2018 at 7:52
  • for a programmer, "retain" means a "strong" reference. A link is at best a "weak" reference.
    – Cœur
    Commented Apr 20, 2018 at 10:06
-6

I find the entire licensing terms on stack overflow bogus....

I have read multiple OP's remarks on multiple meta posts, all leading to the same conclusion:

1) DO YOU REALLY THINK EVERYONE WHO USES STACKOVERFLOW WILL READ META?

Moreover,

2) DO YOU REALLY THINK EVERY PROGRAMMER KNOWS ABOUT LICENSING?

I'm very sure the first thing people on meta will point out is, it is everyones responsibility to do so. However, the truth is far from it.

I quote Murphy's Law here:

"whatever can go wrong, will go wrong."

Even if Stack OverFlow asks you to accept the licensing terms when you have signed up using a new account. The last thing people do when and they are new to something they need to use for a quick solution to a daily problem is read the terms and conditions.

I don't know why:

Releasing all code ever written on stack overflow henceforth under Unlicense ( or the Public Domain ) is harder than creating a new license. Stay with me here.

What I think should be happening is that:

1) All old questions and answers are still under cc by-sa 3.0 (But carry a small, but distinct footer stating these are copyleft licensed)

2.0) All new questions and answers are under Unlicense ( or Public Domain ), unless otherwise stated.

2.1) A nice addition to this, is if stack overflow could provide licensing options before a question or answer gets posted.

2.2) Furtheremore, the licensing prompt could ask the user posting the question or answer if "code" has been taken from other sources with different licenses. If yes, I'm not sure how to handle this, but it's better than no prompt, that's for sure.

This way, those that are more adjusted to licenses have the ability to add them to protect their intellectual rights ( MIT, cc by sa, or whatever). And those that don't, are still educated with being given an option. Much like github's way of doing things. But instead of the default being all rights reserved. It is Unlicensed.

In essence, I conclude by saying that, it isn't about what people should be doing, it's about what they are doing and how to effectively change the wrong attitude.

These are just my 2 cents on the matter. I would love to hear more opinions in the comments.

You must log in to answer this question.

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