Are licenses relevant for small code snippets?

When I'm about to write a short algorithm, I first check in the base class library I'm using whether the algorithm is implemented in it. If not, I often do a quick google search to see if someone has done it before (which is the case, 19 times out of 20).

Most of the time, I find the exact code I need. Sometimes it's clear what license applies to the source code, sometimes not. It may be GPL, LGPL, BSD or whatever. Sometimes people have posted a code snippet on some random forum which solves my problem.

It's clear to me that I can't reuse the code (copy/paste it into my code) without caring about the license if the code is in some way substantial. What is not clear to me is whether I can copy a code snippet containing 5 lines or so without doing a license violation.

Can I copy/paste a 5-line code snippet without caring about the license? What about one-liner? What about 10 lines? Where do I draw the line (no pun intended)?

My second problem is that if I have found a 10-line code snippet which does exactly what I need, but feel that I cannot copy it because it's GPL-licensed and my software isn't, I have already memorized how to implement it so when I go around implementing the same functionality, my code is almost identical to the GPL licensed code I saw a few minutes ago. (In other words, the code was copied to my brain and my brain after that copied it into my source code).

Edit : I'm located in Sweden. It makes me even more confused that this is country-dependent. What if I re-use a piece of code (in a manner which is legal where I live) and I sell this source code to a company in a country where the re-use of code would be illegal.


On the first problem: silly as that law may be, technically copyright applies to any expression, and applies without requiring the author of the expression to assert it explicitly; if there is no license, you might in theory be liable for copyright violation even for small snippets. Possible defenses are based on fair use, but (again, in theory) you might end up in court to defend yourself with that (your fair use claim does not stop the copyright holder from suing -- nothing does, except common sense -- but the judge might decide in your favor if he or she decides the use is indeed fair).

Your second problem hinges on whether your code is a derivative work of the snippet, another thorny concept which mingles with the "fair use" issue. Again, the only definitive answer is the one a judge gives in the specific case ("definitive" unless overruled by an appeals court, actually;-).

Remember, most lawmakers are lawyers by training: sometimes one may wonder if they make the laws subtle and difficult just in order to ensure lawyers will always have plenty of jobs;-).


It largly depends on country. In some countries programs are threated as pices of literature so small amount of 'quote' is allowed as a fair use.

Unfortunatly you have to state which country you live in and check what's the local copyright law. In most cases cheaper solution is mailing author for permission (especially if it is open source project).


Copyright law (as in the Berne Convention) protects even small pieces of writing to some extent, so you'd have to consult somebody knowledgeable in the law where you live. There may be something available locally in a library, or you could consult a lawyer.

As far as what happens when you do something legal in Sweden and send it to me in the US where it might be illegal, I don't really know. I think I'd be the one in legal trouble, although there's the Dmitri Sklyarov case to worry about (he did something legal in Russia, came to the US, and was arrested under legal circumstances I don't really understand). Again, consult a lawyer.

链接地址: http://www.djcxy.com/p/79490.html

上一篇: 使用GeoDjango需要postGIS性能

下一篇: 许可证与小代码段相关吗?