Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been looking for various licenses that I can use for an open-source project of mine, but all of the projects that I've seen, with all kinds of licenses, appear to have a giant, obnoxious (in my opinion) notice in each source file that states that the file is listed under a certain license. I don't think that I've found a single source project that isn't public domain that doesn't have a notice like that.

This just seems like a waste of time and file space. I plan on putting @license and @author tags in my projects, but I don't see why I need to list such a giant notice in each individual file if I don't want to make my code public domain.

Is there any reason why I would want to include such a notice in my projects, or would simply including a notice in the README and a @license tag be good enough? Does this affect the "clearly stated" rule of most licenses, or is it just overkill so that people won't argue?

share|improve this question
6  
Your editor should allow you to fold/hide the license into 1 line. – Pubby Dec 18 '11 at 16:34
1  
Realistically, if someone steels your code, renames a variable and remove the copyright would a court of law consider these 2 files identical? – NoChance Dec 18 '11 at 17:01
3  
@Emmad: No, a court would not say they are identical. (But they might be "essentially identical".) Yes, a court would say it's copyright infringement. – Andrew Dalke Dec 18 '11 at 18:49

In my understanding, the GPLv3 strongly suggests (or even perhaps requires, at least that how I understand the text How to Apply These Terms to Your New Programs, after its section 17) a copyright notice in every source file. It says

To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.

<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year>  <name of author>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

And GNU projects which are FSF owned, like GCC, have such a notice in every file.

I also know of a program (J.Pitrat's CAIA system) which has been refused on a free software community web site because it had no such notice in every file.

I am not a lawyer, but I believe that such notice is practically mandatory in every source file of a GPLv3 program.

share|improve this answer
5  
It can't be mandatory because there are systems, like Smalltalk images, which don't express source code as files. They say "safest" and "should", not "must." What they recommend is an easily understood guideline with little chance of someone making an error, but it is definitely not "practically mandatory." – Andrew Dalke Dec 18 '11 at 18:33
    
I agree, and I said "source file" on purpose. Actually, CAIA's system is a bit like Smalltalk: the image is in data files, and the CAIA "source files" I mentionned are generated C files. However, my GCC MELT (a branch of GCC, under FSF copyright) is also meta-programmed, and I do take care to generate copyright notice comments in generated C files (and I put them in hand-written C & MELT code). – Basile Starynkevitch Dec 18 '11 at 18:36
    
Point taken. I know now one paragraph about MELT. In general it's best that generated files include the copyright notice as it's very hard to "attach" the license otherwise. Eg, "yacc" and "lex" are restricted in what they can do. – Andrew Dalke Dec 18 '11 at 18:57
    
To be picky, it might be difficult to generate a year for the copyright of generated files. GCC itself has a small issue about that for gengtype (the generator of code for the garbage collector inside GCC), but nobody really cares... – Basile Starynkevitch Dec 18 '11 at 18:59
    
I would downvote if I could. This is pretty specific to the GPL, and/or GPLv3, and the question doesn't mention that... – Josh Jul 8 at 0:59

I've seen many projects which only mention the license in the README or in a LICENSE or COPYING file.

Your software is automatically covered under copyright, as agreed in international law. (Unless you are working for the US government or some other organization for which copyright does not apply.)

If someone uses your software then they must make sure to follow the license agreement, or follow the fair use restrictions on what they can do.

Suppose that person wants to use one of the files in your code distribution, which of course requires a copy and hence copyright law applies. By default they do NOT have the right to use your software under copyright law. It's only when they know and follow the license restrictions that they are allowed to use it.

So if they use a file without a software license then they are breaking copyright law. Since all the licenses say something like "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software", they are obliged to put that license somewhere.

That can be in the file itself, or when I've used code as library I put the relevant portions into its own directory and added a "README" or "LICENSE" into that subdirectory.

In short, you don't need to put the license in each file. I think it's overkill. There's no extra legal protection in doing so. It does help a downstream user somewhat, but not by much.

I think the tradition of lots of comment-based metadata (license, creation date of each function, changelog, etc.) are very old traditions which exist because they are easy to do and which more a talisman than useful.

For example, the default Eclipse template adds what I think of as useless metadata before each function, which I think is much better captured by version control. But that practice is common in many shops.

share|improve this answer
1  
For example, I don't see anything related to licensing in Rails source files at all. – Anton Barkovsky Dec 18 '11 at 18:49
1  
And of the 200 files in the top-level Python standard library, only 34 contain the word "copyright", and only 4 of those are for the Python Software Foundation, which controls the copyright to Python. – Andrew Dalke Dec 18 '11 at 18:58

The problem is that it's very easy to dis-aggregate a single source code file from its larger project, such as someone just checking out, emailing, downloading one file, without the rest that contains the full copyright. And then that file can get passed along ad-infinitum into time, to Nth parties who may have no idea of the files origins.

The copyright notice at the top reminds anyone who runs across that lone file that it is in fact copyrighted, not public domain, and thus some license may or may not be involved in its distribution or use. Versus letting the finder make their own random assumptions.

share|improve this answer
3  
Isn't it just as easy to dis-aggregate through copy-paste various fragments of a source file as well? What then? This argument seems inconsistent to me. – Travis Griggs Feb 19 '15 at 23:59

There is no secret superpower meeting in an underground bunker that says what you must put it in each source file.

It does make it clear to the user that this file is under whatever license and in fact most GPL software contains a short preamble saying to read license.txt. Remember projects get split up and files get reused so only putting the message in a single file might not be a good idea.

If in the unlikely event it ever went to court you might have more claim if you had clearly marked each file as your work and what license it was under - then nobody could claim they thought that this prticular file wasn't covered

share|improve this answer

There is a difference between license and preamble.

In some of my projects I am using the GNU General Public License, Version 3.0. The GNU GPL makes it necessary to have a preamble on every source code file:

The preamble and instructions are integral parts of the GNU GPL and may not be omitted.

Source: http://www.gnu.org/licenses/gpl-faq.html#GPLOmitPreamble

So here is what I do:

1. Add License.txt

To follow the rules I put a LICENSE.txt in the root of my project's repository. This is also suggested by GitHub (see "Where does the license live").

2. Add preamble using auto fold

Next I include the GPL preamble on top of every source code file BUT to make it hardly disturbing I hide it in the IDE. Most IDE's have a feature to automatically fold code blocks. NetBeans has support for Custom Code Folding and WebStorm supports folding comments too.

So here is how it looks like:

//<editor-fold desc="Preamble">
/*
 * Company Name
 * Copyright (C) 2016 Company Name
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * ...
 */
//</editor-fold>

console.log('Here is my licensed JavaScript code.');

I think this is a very good compromise between comfortability and legal security.

If you have lots of projects where you need to add a license, then http://www.addalicense.com/ might be of help.

Please note: My advice refers to GPLv3. Other license types might not require a preamble.

share|improve this answer

I almost posted a remarkably similar question. Less about annoyances and more about technicalities. TL;DR: I believe the answer is a matter of the author's priorities. Maybe intent would be more accurate than priorities...

I believe it is okay to reference a license in your source, depending on your definition of "okay". Lets agree that the term "unaccompanied" indicates a source file that is part of a project which has been ruthlessly separated from it's loving code base. Said file contains a line like this:

# This file is covered by the LICENSING file in the root of this project.

Or a much cooler line like this:

* @license OMGBBQ <http://goodlics.com/bbq>

"But wait!", you exclaim, "you just said that file was separated from its project! And goodlics.com redirects to a domain squatter! Stop being to trixy!" You are correct, I did say that, but that might be okay, and stop yelling at me. Here is my not-a-lawyer reasoning:

  • Almost every country has agreed to the [feel the] Berne Convention, which AFAIK means that if you create something, you have copyright on it, period. You don't need a (c) line or any crap like that, but that stuff (plus a third-party VCS like GitHub) does make it easier to prove that you created it and when you created it.
  • Therefore, if you post some juicy 1337 code online that you created, you have copyright on it. Nobody is allowed to (legally) copy it. It's rare, and shocking, I know, but I've heard that people break the law sometimes. That's still possible.
  • That awesome nyancat-bcminer-algo.qbasic file you wrote and posted on LiveJournal is, believe it or not, not public domain. Not unless you say it's public domain. By default it is yours and yours alone. It's...Precious. (At least for 25-50+ years, unless you're Disney.)
  • People conventionally communicate this intent (making some or all rights not yours and yours alone) via licencingses, but you need to announce that intent; it's opt-in opt-out (HAHA GET IT? opting in to opt out of your copyright? AWESOME). Get your tickets out, we're almost there!
  • If it is okay that the aforementioned unaccompanied files are private domain--that is, not legally copyable, then using a potentially-broken reference is perfectly fine. However, if it is not okay, then I think you need to include the license text within every source file. That way, unaccompanied files are still sure to be licensed the way you prioriti--intended. Yeah, that's better.

This reasoning makes two epic and probably-invalid assumptions:

  • A "broken" license reference falls back on default (copyrighted) behavior, which may not be a valid assumption.
  • That site you posted on doesn't have some sort of posting policy (like StackExchange) that makes everything public domain.

Thank you for riding monkey-brain airways.

Disclaimer: This seems logical to me to I am 90% sure that I am 100% wrong.

share|improve this answer

protected by gnat Jul 8 at 10:46

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

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

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