26

Is there a size where you can copy under fair use for code you don't have a license for the purpose? For example, what if I copy a snippet that is (normally) 3 lines of code? Is that fair use? If it is fair use, what length is required before I need a license?

closed as off-topic by Jules, Bryan Oakley, gnat, Greg Burghardt, jwenting Jul 23 '18 at 5:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking for legal advice or aid are off-topic here. You may be able to get help with understanding, applying, and complying with free and open licenses on Open Source. You may be able to get help with legal terms, concepts, language, and procedures on Law." – Jules, Bryan Oakley, gnat, Greg Burghardt, jwenting
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 11
    Laws vary depending on where you are, and there are people here from all over the world. When asking a legal question, please tell us where you live and work. Moreover, don't trust anything we say. If it's important to you in some way (like financially), consult a local lawyer with appropriate experience. – David Thornley Oct 15 '10 at 17:11
  • 1
    Note: I've added an answer to this question because I don't feel the existing answers are sufficiently correct, despite the subject being offtopic according to current guidelines -- I think having incorrect or misleading answers is a worse situation than posting new offtopic answers. – Jules Jul 22 '18 at 12:33
12

In the US, the legal doctrine of Fair Use does not apply to embedding excerpts of copyrighted works into source code. How such doctrine is applied by the laws of your jurisdiction may vary.

I will excerpt from a US Copyright Office article on Fair Use, and of copyrights generally:

Section 107 contains a list of the various purposes for which the reproduction of a particular work may be considered fair, such as criticism, comment, news reporting, teaching, scholarship, and research [emphasis mine]. Section 107 also sets out four factors to be considered in determining whether or not a particular use is fair:

  1. The purpose and character of the use, including whether such use is of commercial nature or is for nonprofit educational purposes
  2. The nature of the copyrighted work
  3. The amount and substantiality of the portion used in relation to the copyrighted work as a whole
  4. The effect of the use upon the potential market for, or value of, the copyrighted work.

The distinction between fair use and infringement may be unclear and not easily defined. There is no specific number of words, lines, or notes [emphasis mine] that may safely be taken without permission. Acknowledging the source of the copyrighted material does not substitute for obtaining permission.

It summarizes the legal limits of copyright, which Fair Use further limits, like so:

Copyright protects the particular way an author has expressed himself. It does not extend to any ideas, systems, or factual information conveyed in the work.

The safest course is always to get permission from the copyright owner before using copyrighted material. The Copyright Office cannot give this permission.

What the limits of what copyright protects tells us is though you cannot copy "snippets" of code via Fair Use, you can rewrite the way ideas, systems (including algorithms), or factual information are expressed in those snippets.

In short, 3 lines of code should be small enough for you to rewrite it so as not to violate the original work's copyright. It probably took longer to write your question than it will to do the rewrite.

  • 13
    I don't see anything in here that says that copying a snippet of code cannot be fair use. It explains the criteria that will be used to judge whether your use is fair use, if you get sued. – KeithB Oct 15 '10 at 16:00
  • 7
    The list is intended to be exemplary, not complete. That's why it contains the words "such as". If the code is largely functional, only a small section of the original work is taken, and the two works do not compete in the market, it's quite possible courts would find fair use. – David Schwartz Sep 4 '11 at 4:00
  • 4
    And what qualifications do you have to "expound on the law", @Huperniketes? You've written this as though you are quoting an authority that definitively shows copying code not to be fair use, but in fact you're just performing your own interpretation of statute without even citing any case law. – Mark Amery Feb 20 '15 at 22:23
  • 6
    That's actually irrelevant to my point. The problem is that a list set off with "such as" is not exhaustive in any version of English, not even the bizarre English-from-Mars that attorneys speak on a day-to-day basis. The list you italicized is a list of examples, nothing more. It contributes nothing whatsoever to the actual meaning of the law, beyond acting as a hint to judges and lawyers about the general intentions of the lawmakers. Fair use is an incredibly gray area of law, and presenting any part of it in such black-and-white terms does your readers an enormous disservice. – Kevin Mar 4 '15 at 3:29
  • 6
    @Huperniketes, you claim I am making idiotic assertions without knowing the material when I have asserted nothing about the law. You are the one making the legal claim - that, contrary to a plain English reading, your italicized passage shows that copying code snippets into software can never be fair use. I am sceptical of that claim, but sure, I don't know any case law to support or disprove it. Which is why I'm not making factual claims. The burden of evidence is on you if you want to be believed, but you've chosen to sneer at and insult those who neutrally ask you to show evidence. – Mark Amery Mar 7 '15 at 14:01
20

I am not a lawyer.

However, you are absolutely free to use the following 3 lines of code in anything that you write:

for (i = 0; i < 5; i++) {
    printf("I am not a lawyer!\n");
}

.... That's purely functional code (not functional in the sense you might think, but functional by what it does). It doesn't actually accomplish anything; it simply exercises the constructs of the language. It supports stuff that does actual work, you type it often enough that you have a macro to produce it. But what you're talking about isn't 'fair use', it's is this even copyrightable or licensable in the first place?

The only correct answer here is ask a lawyer. Ten lines of code from what? A highly specialized sorting algorithm? Some kind of firmware? One of the millions of configuration file parsers that have been floating around since the dawn of usenet? Code generated by another program that generates database classes based on your DB schema?

But, prove to me that you wrote that for loop, or switch statement, and didn't just copy mine. At the point where assertions stop sounding absurd, you're probably at the point where you should talk to a lawyer, or at least your engineering manager / PM / etc.

I participate in several free/open source projects, some of them require a copyright assignment for anything not 'trivial'. All of them that have this requirement define 'trivial' to be ten lines of code added or modified. But that's just an arbitrary litmus test to establish some kind of standard; one line of mind-bending byte comparison is much more likely to be subject to copyright than a 10 line switch.

My snippet gallery consists of hundreds of functions, all of them have the original author's information in doxygen style comments, as well as license info (if any, most are just public domain).

Unless clearly trivial (as in my humorous example), I would not re-use code unless I know that I have permission to do so. I also, always, follow the rules of whatever license applies. And to help my future self (or future maintainers), I like leaving a link to where I found stuff in a comment, even if that's the name of a tar ball I turn in on a USB stick if I leave the company.

  • 2
    I very much doubt many snippets are in the public domain. – Martijn Jul 23 '11 at 16:24
  • 2
    I'm late to the party, but it's also important to note that even if Tim Post retained all rights to the code above, he cannot copyright the idea. If you learn from that snippet that you can print a string five times by using a for loop, and then you write your own (remarkably similar) for loop using those ideas, then you are fine regardless; it doesn't matter what Tim wants. Depending on how long it is, and how similar your version is, you might have a burden of proving that you did actually re-implement it, but if you can do that, you are guaranteed in the clear. – GrandOpener Dec 20 '15 at 23:15
  • While copyrights don't protect ideas, patents do. Copyright is a legal term, having a specific legal definition. Ideas cannot be copyrighted, but the way they are expressed can and are; and under current IP law, a creator's work is automatically copyrighted and protected. An idea can be patented if it meets the corresponding standards. – Huperniketes Sep 10 '16 at 14:55
  • @Huperniketes - "the way [ideas] are expressed can [be copyright] and are; and under current IP law, a creator's work is automatically copyrighted and protected" -- as long as the expression of those ideas reaches a level of originality and inventiveness that is regarded as a minimum threshold of creativity to warrant protection and the amount of copying is not considered trivial. If the expression is not sufficiently distinctive or the amount of copying is considered trivial, this is called de minimis copying and is not covered by copyright. This has been found to courts to extend to ... – Jules Jul 22 '18 at 11:59
  • ... computer programs in the situation where they are obvious minimal programs that perform a particular operation (and where the operation itself is not innovative). E.g. several cases of this are discussed here. In the context of the question, those 3 lines referenced are almost certainly in that category: entirely functional rather than creative in nature, and almost certainly performing a common operation that is found in many pieces of software. In this case, they are probably not protected. – Jules Jul 22 '18 at 12:00
1

Copyright applies to creative works, including expressions of ideas (which is how source code is treated legally speaking), as long as the expression of those ideas reaches a level of originality and inventiveness that exceeds a level regarded as a minimum threshold of creativity to warrant protection and the amount of copying is not considered trivial.

If the expression is not sufficiently distinctive, this is referred to as not reaching the threshold of copyrightability; if the amount of copying is considered trivial, this is called de minimis copying and isn't covered by copyright. This has been found by courts to extend to computer programs in the situation where they are obvious minimal programs that perform a particular operation (and where the operation itself is not innovative). E.g. several cases of this are discussed here and here.

In the context of the question, those 3 lines referenced are almost certainly in that category: entirely functional rather than creative in nature, and almost certainly performing a common operation that is found in many pieces of software. In this case, they are probably not protected.

Technically this isn't actually "fair use", which is a specific statutory exemption from restrictions that a copyright holder is entitled to enforce, but is instead based on common law case precedents that have accumulated over time, but the term "fair use" is often used loosely in a way that includes both meanings, and there is in reality substantial overlap between them.

1

The US "fair use doctrine" is a possible affirmative defense against a claim of copyright infringement. "Affirmative defense" means that you admit copying without license and therefore infringing on someone's copyright, but then you claim that for some reason you have the right to do this without negative consequences. To be honest, that seems to be a dangerous strategy. You propose to write code that infringes on someone's or more than one person's copyright and rely on a fair use defense. I could very easily imagine that 3 lines of code may be "fair use" but 3 lines here, 3 lines there, and 3 lines elsewhere isn't.

There is a much better defense against copyright infringement: Don't infringe in the first place. Instead of copying a code snippet, you read it, you examine it closely, you learn how it works, you understand it, and once you completely understand it, you don't copy it but write your own three lines of code. This has multiple advantages:

  1. You are not committing copyright infringement.
  2. You learned something and become a better developer.
  3. Writing it yourself means it is written in the same style as your other code, making maintenance easier.
  4. While spending the time to understand the code snippet, you learn about its inadequacies, its limitations, its bugs, and avoid them in your own code, which means your code is better than if you had copied the snippet.

Not the answer you're looking for? Browse other questions tagged or ask your own question.