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

Is it ok to put a GPL notice inside a small script or a snippet?

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/.

Or will just the Copyright notice be enough?

share|improve this question
    
Why do you need to attach a license to a snippet of code? If it's that precious, don't share it. If it's not precious, there's no need for a license. – Bryan Oakley Mar 18 at 23:25
up vote 7 down vote accepted

You are correct that you should:

  • Assert Copyright
  • Grant people explicit rights to use, modify and distribute your code.

In many places, the idea of public domain is not recognized. In order for someone to be able to (legally) use your code, there must be something that says that they can, and under what conditions. For snippets, I highly recommend the 3 clause BSD style license. It asserts your copyright, tells people that they are free to do whatever they like with the code, so long as they preserve your copyright when distributing it via source and tells them that they can't use your name to endorse derived works of the code without your permission.

The GPL has very specific definitions of what should happen when you combine GPL covered work with something else. The GPL has to prevail as the dominate license in the code base, which means someone using your snippets inherits the GPL. The LGPL (known as the library GPL, or lesser GPL) is more suited for that, because it allows linking without inheriting the license. Still, if you're going to take the teeth out of the GPL, you might as well use a much simpler license.

Another excellent choice would be the MIT license, which is very similar to the three clause BSD style license.

Finally, if you must use the GPL, please indicate "Version 2 or later" if at all possible. This ensures that your code can work in places where a tree might be using "Version 2 Only", which is quite common. A substantial portion of the Linux kernel specifies version 2 only, GPL3 (while widely accepted) was met with a fair amount of criticism and rejection.

I'm not discounting the importance, significance or usefulness of the GPL. I'm just suggesting that it might not be the best choice for snippets and libraries.

share|improve this answer
    
Well explained. Thank you. – Ruel Nov 26 '10 at 6:40

Everything you need to know about that should be here:

http://www.gnu.org/licenses/gpl-howto.html

Out of curiosity, why would you make a snippet GPL? Making a code snippet GPL pretty much makes it useless for anyone except those writing software that is also GPL. Seems to me the LGPL (or even the MIT) license would make more sense.

share|improve this answer
    
Actually, the snippets were intended for open source projects. That somebody may find it useful for their projects, and use/modify it for their code. – Ruel Nov 26 '10 at 3:53
4  
Not all open source projects are GPL. In fact, many aren't. – Robert Harvey Nov 26 '10 at 3:58
    
Agreed with Robert Harvey. The implications of making something GPL effectively causes a flow of GPL to anything the uses it. There are some very long Q-and-A pages you should read, because imposing GPL can cause significant problems for others (including other open source not using GPL). A more generous license would create less trouble for others. Personally, I like the Boost license: opensource.org/licenses/bsl1.0.html – quickly_now Nov 26 '10 at 8:53
    
A useful reference for some of the many open source licenses: opensource.org/licenses/index.html – quickly_now Nov 26 '10 at 8:55

The GPL is a pretty heavy-weight copyleft license. The idea of copyleft is that you allow anybody to use your work but prevent them from building works upon it without granting their users the same rights. For a substantial project, this is an effective way to avoid somebody taking your free software project, polishing it a little and then re-distributing it as non-free software that is advertised as a superior alternative to your project, thus effectively harming your project and its users with your own weapons. It is a pretty heavy-weight license, though. For example, it has fairly complicated rules about how derived works may use the copyrighted code and requires those who build upon your work to publish a copy of the entire license along with the software. Even the short boilerplate text is fairly long. If you think that this weight is not compensated by the safety that copyleft gives you, you might reach for a simpler permissive license that allows users to do anything they like with your software but not sue you for any damage. The Free Software Foundation recommends the following text for this purpose.

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.

Don't forget to still add your name, year of modification and e-mail address so users can contact you and give proper credit when citing or re-using your work.

The MIT license, as others have recommended, is a somewhat more elaborate choice that basically achieves the same purpose. I would use the all-permissive license quoted above for short examples and other snippets and the MIT license for small but fully functional works you publish. For substantial works, I would use the GPL3+ license. Don't publish your work without any copyright notice, though, as it confuses honest users and effectively makes your software (even small pieces) non-free.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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