views:

97

answers:

4

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.

A: 

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

Maciej Piechotka
I've edited my original post. (I'm located in Sweden.)
Martin
A: 

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;-).

Alex Martelli
Laws are subtle and difficult for the simple reason that they have to be precise ways of dealing with human behavior, and they try to embody some sort of justice. The corresponding programming equivalent would be some areas of AI.
David Thornley
@David, I once (late 80's) helped researchers from a university's Law School set up an "expert system" -- they cleverly picked a small, self-contained field not subject to political/ideological pressure...: fishing regulations on (Italian) inland waterways. They were less than 1/3rd into entering all applicable laws and regulation when... the first self-contradiction appeared, and the whole project became useless (it used normal Aristotelian logic, not fuzzy or probabilistic, so, given a contradiction in "axioms" [laws], it could, and would, find a proof for *any* theorem).
Alex Martelli
And the point of that anecdote is, @David: I think you're making excuses for lawmakers' sloppiness (including judges': many contradictions arise from precedents established by sloppy court decisions;-). It shouldn't be beyond the ken of man to establish precise, clear rules on what boats you can use on what bodies of water at what time of the year, what kinds of nets, what lures -), but surely not rocket science. (There MAY be programming equivalents;-).
Alex Martelli
A: 

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.

David Thornley
A: 

I am not a lawyer - but i've recently been involved in looking at issues like this. Copying and pasting code from blogs can certainly be considered copyright infringement unless the blog states the license that the code is under and how it can be reused.

I'd recommend using sample code like this only to give you the general process/idea for a solution - then reimplement the idea from your own head and in your own style.

As also suggested, mailing for permission is another alternative. Most people blogging code are open to having it reused.

Robert Conn
Regarding the "from your own head".When I do this, I often come up with an implementation almost identical to the one I've seen online. In some cases, it may be something simple, such as searching for a string in another string.
Martin