Disclaimer: I know you're not a lawyer! :)

This question is for university assignments, not work nor personal.

Say I'm looking for the implementation of something very very specific, and I find that in an open source project (say, using google code search).

The thing itself is about 20 ~ 30 lines of code, and constitutes less than 10% of one file from the project which contains tens of other files.

Also, say the license is Free, but mandates that you don't remove the license.

Something like:

Permission to use, copy, modify, and distribute this software for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both the copyright notice and this permission notice appear in supporting documentation
etc etc ..

In that case, would I be violating the license if I just copy those lines, cite the source, but without copying the entire license text along with it?

Given that I do cite the source of these lines in a comment right above them.

In other words, what should I do in order to avoid violating the license without cluttering my code with legalese?

Most of the time this very specific implementation is of some mathematical formula (involving things like fft, quaternions, etc), where I know for sure that the author of this code didn't "invent" the math behind it. It's no where near a substantial part of the software.


This is not about GPL specifically. I apologize for the confusion (I removed the gpl tag).


I'm not trying to argue whether it's ok or not, I'm asking because I'm pretty much clueless about these kinds of things.

I'm essentially assuming/hoping that if I put a link to the source and the link contains the license information, then it would be ok.

Also, my understanding is that, the point of the license, is to prevent people from "leeching" these files and removing the license notice at the top. Where as I'm not copying the file itself, only a small part of it.

Essentially what I would leave is something like:

   The following function has been taken from <project name>
   <url to the original file>

The file pointed to by the url contains the license of course.


I just wanted to add, it's not really 20~30 lines, more like 5~15, (I wanted to make the question a bit general) and this is not about a specific case that happened to me now, it's happened more than once, and I assume it could happen to any university/college student.
You're working on your assignment, and you need this helper function or that, and it's not even in the core of your assignment. google code search, and, great, you find this helper function, and it's open source!! but you're not sure the best way to properly cite it, and not sure whether you really need to put that license in the middle of your code.

+1  A: 

If this is for your employer better run it through legal. If this for a personal project, I'd say it's alright. If you are going to use it for (personal) commercial purposes you need to have the copyright at the top.

it's not really GPL but no other example came to mind because I don't memorize names of various licenses
hasen j
MIT, Creative Commons are some other. All of them have similar requirement but of varying strictness.
+12  A: 

Ethically (not legally) if you're copying and pasting code, you should cite the source. Beyond ethics, it's also helpful to cite the source so you or your maintenance programmers can go back to it again later.

Bill the Lizard

"Disclaimer: You're not a lawyer!"

So why ask? will agree with you

Display the licence.

because there's a difference between "I'm illiterate in legalese" and "maybe I know but don't take my word as cannon because I'm not prepared to get in trouble as a reward for helping you"
hasen j
+3  A: 

Provide some comments around the block of code that briefly describe the license and leave a url. This is especially important for schoolwork since the graders might hit your code with a similarity-testing program, and I would imagine a chunk of 10-20 lines might trigger it. Before copy-pasting, you should also make sure that it's legit to do this for the assignment.

Andrew Keeton
+2  A: 

Aha -- the intellectual property question.

What you should probably do is try to find some other source (code, paper, or expired patent) that uses the same or similar algorithm as the one in the software you found -- let's call that software you found "Package X" -- and avoid Package X by using a different source.

It sounds like maybe the 10-20 lines of code in question are tangential to the core purpose of Package X. If this is the case, then it's likely that such an algorithm exists somewhere else that's not covered by GPL, and if so then you're home free (assuming they didn't get their code from Package X like you were thinking of doing).

If the 10-20 lines of code you wish to use are part of the core innovations of Package X, you may be stuck. If it's not for personal use, including those lines w/o also including the license, is a potential ticking time bomb. (edit: even if it's for academic use, the GPL is "viral" in that it would make your whole package covered under the GPL: see GPL section 5c. Other open-source licenses don't have this problem.)

Jason S
+25  A: 

Clearly you would be violating the license if you do not include the text. It's so obviously written I can't see any reason why you should think otherwise. Legally and ethically you are obliged to do so, period.

However if you can live with yourself you'd most probably get away with it, but of small things like that the soul begins to rot.

EDIT:- and from your comment it seems to me, if you're honest with yourself, that you're really asking stackoverflow to salve your conscience by saying to you it's fine to do this because you're only copying just a teeny-weeny little bit.

As you'll recall this "they've copied little bits" is precisely the argument that SCO used when they attempted to gain copyright over Linux, and it's pretty obvious from that that the "we only copied little bits" argument would have given them the big win if they could have proven it.

The point is, it's nowhere near a substantial part of the code, and I do plan to cite the source. The question is about copying the entire license along with it.
hasen j
But does the licence specify anything about copying just bits of the code? Not as far as you've shown. You're effectively trying to argue that the licence doesn't apply because you're only using a little bit of the code - what grounds do you have for this argument?
Jon Skeet
It's not an argument, I'm clueless about these things. I'm assuming that if I cite the source and put a link to a url that has the license, then it would be fine.
hasen j
Cruachan, maybe there's a bit of truth in that, but I'm not asking people to solve my problem, I can usually consult with my professor whenever I copy something. I want to know what other people think.
hasen j
Funny how many programmers I've known get all bent out of shape over copying open source software, but have no problem illegally downloading music. I don't condone either, just find it interesting.
For what its worth, Jon's use of the word "argument" means "logical assertion of fact". I believe he is asking you to support your claim that the quantity of code used invalidates the clear wording of the license.
Andrew Hare
Software licenses are based on copyright, and copyright infringement is assessed partly on how much of the work was copied compared to the whole. Using a very small portion without permission might be defensible. The smaller the code snippet, the murkier the question becomes.
Adam Lassek
Also, the functionality of the code makes a difference as well. If it is purely a mathematical algorithm, it is probably not subject to copyright at all.
Adam Lassek

Ethically: It's wrong. Legally you want to find out what constitutes "a substantial part" of the project. So you should: Write an email to the FSF.

+1  A: 

The only situation where this could possibly come close to being ethical is if the code is in the public domain. Even then you're cheating yourself by not citing your source. It's plagiarising, just as if you wrote a paper. And yes, as said in the text of the license, you must include that license in whatever it is you're writing. It should be fine if you just put something like /* This code belongs to _____ ©. See LICENSE for details. */, but seeing as how you said it's for a school project, that doesn't seem possible. Really ask yourself if you want to be a copy paste sort of "programmer".

what? I'm a copy-paste programmer if my project has thousands of lines of code and I use 20 lines implementing some math from a free project?
hasen j
Look at what I said from my perspective. University student doing homework wondering if it's okay to copy someone else's code for his/her assignment. You can't expect me to know the situation entirely.
+3  A: 

Either cite the source, or learn the concept of what the code does and implement it your own way. 20 lines doesn't sound like a bunch and you could maybe even do it better.

+1  A: 

The thing itself is about 20 ~ 30 lines of code, and constitutes less than 10% of one file from the project which contains tens of other files.

If it is only 20-30 lines of code then I think it would be better to just re-implement it yourself. It shouldn't take too long, and then there are no legal/ethical worries. This is not feasible only if you need to spend an enormous amount of time re-implementing the code, in which case it is probably not a trivial thing that you are copying.

+2  A: 

Also check out a similar question I asked not not long ago.

Mark Renouf
+23  A: 

A good rule of thumb to follow: if in doubt, ask the author. If you get the author's permission, chances are good that you'll be ok both legally and ethically.

In other words, what should I do in order to avoid violating the license without cluttering my code with legalese?

Legally speaking, I believe you have to give the license text with the code (unless the author is willing to make an exception for you). This is why a lot of open source projects require that contributors assign copyright to them.

(insert standard I am not a lawyer disclaimer)

Jason Baker
+1 for stating the elusive obvious: when in doubt, don't just ask the interwebs / comb through license terms / Google it. Just ask nicely. Most people are actually cool with it when you ask first.
Jens Roland
+7  A: 

I teach post secondary programming courses. I (and other instructors I know) would have no issue with a student making use of other code provided that it is clearly set out who wrote it - otherwise you are going to get nailed for plagiarism (we really don't like plagiarism).

20 lines out of an entire project is not that much. If you took 95% of the code from other sources I'd not be happy (and your mark would reflect that - probably a zero).

From a moral point of view, how would you like it if someone took your work and claimed credit for doing it?

From a legal point of view, if you remove the license and the licese forbitds that then you are likely in "trouble" (not that I think anyone would do anything from a legal point of view).

So, given that you have to cite where you got the code from (or risk plagiarism accusation) there is no point in removing the license.

I'd go ask your instructor to see what their opinion on the matter is.


Essentially what I would leave is something like:

/* The following function has been taken from */

The file pointed to by the url contains the license of course.

As an instructor I would be ok with that... (as I would be as an open source developer) again go ask your instructor what they would say.

In a "real world" setting I would say that you cannot do that (especially in the case of GPL) - doing so could put your company at risk.

From a legal point of view (for this particular case) you may actually need to license the code in question as the same license though.

I agree. What's the point of removing the license. The original poster states "without cluttering my code with legalese". I don't go for that. Just put it in the code and be done with it.
The percentage-of-code argument is slippery. What may be 5% of someone else's borrowed code could be 80% of yours...
Andrew Vit
The % is a subjective thing. My students get zero when they deserve it (usually a total of 100% copied code). If I don't think it will hold up on appeal I don't make the accusation. I have yet to have an appeal.
+1  A: 

You shouldn't reinvent the wheel, but you should give others credit for their work. Cite your sources.


John T

Refactor the code so that it doesn't resemble the source. Be creative and try to make it more efficient. I think that if you did that you wouldn't need to display the license.

Ronnie Overby

If it isn't complicated (eg math) code you could try to write it yourself.

If you use the original code you must follow the rules defined by the license - if it is GPL you are allowed only use it if your company isn't going to ship to users the software you are developing, meaning if it is for internal usage. You can USE GPL code for commercial purposes, but you can't ship products based on it. If it is other open source license you probably can use it.

Often the code from other project isn't usable directly without significant modifications.

GPL can't be used to develop commercial software?? get your information straight buddy. If you read the question, code of this kind is often heavily based on some math beyond my current level of understanding.
hasen j
Then try to understand what it does - if you don't understand the code you can't use it anyway. And yes you can't use GPL code in your commercial non GPL product if you are shipping it.
The OPs example with FFT is a good example of code that you better not write yourself (unless it's a university assignment).
You certainly can ship GPLed code for profit. Red Hat is the first company that comes to mind that does it. It doesn't fit with all business models, but your blanket statement is wrong.
David Thornley
Of course you can ship GPLed code :) But it is legal only and if the whole product, that you are shipping is also GPL.
+1  A: 

Your question lead to some spirited discussion. Thanks for asking it.

I'd say that ethically, you should cite the source and provide the license in a separate file. It should also cover you legally, but I'll leave that to the IP attorneys.

What I find interesting is that algorithms are a naturally occurring pattern that solves a problem--programming is the capturing of those and codifying them. IMHO, all algorithms are free and open-source. Much as the Universe and it's processes are...

I guess I'm feeling a little philosophical. Fun stuff.


Just copy what it says in your own words.

(Not that most people care about licenses anyways.)

+1  A: 

One thing that hasn't come up yet that I've seen is not the broader intellectual property issue, but the academic honesty question.

Are those 20-30 lines a critical aspect of your assignment you haven't been able to work out yourself? If so, you are probably crossing the line even if it is just 10% of your total code. If you got caught, I wouldn't be too surprised if you ended up with a zero on the assignment (or worse, facing academic dishonesty charges).

If it's some auxiliary function (I don't, some pretty printing function or something), I'd at least cite the work in your code.

Your professors probably don't care if you're finding some libraries to safe time, but if you're yanking parts of your assignment off the 'net they won't be pleased.

+1  A: 

I am too busy now to do detailed research on fair use. Besides you don't give us enough facts about the code. I would say the size portion of the fair use test is likely satisfied. Also use and and purpose as it sounds like your work is transformative not derivative. It also does not sound like you hurt the value of the original product. The rest you have to figure out yourself.

So from an overall perspective: From an academic point of view, you cite the work, you make sure that the portion of your work that is from the taken work is clearly delineated.

From a legal point of view, you are probably OK ( and I do emphasize probably ). In any event. I doubt the original writer would take action, if he ever found out which is unlikely.

+3  A: 

Isolate the required functionality in a separate library and link your original code to that library. Supply all required licenses. This creates a clear distinction between internal and external code.

+5  A: 
Greg Ball

Good question, I did wonder about it myself when I was taking a programming class. My feeling is that it's ok to copy a few lines of code as long as you give the code its original source and you don't plan to distribute the code. My professor didn't object to it.

+1  A: 

It would be much better to cover your behind and cite your source, even if you are not using all of the provided code sample. If you wish to learn how to do something, study the code sample, and then rehash it from your own brain without copy/paste. When I was in school, I never had a problem using other code so long as I a) cited my sources, and b) the core concepts of the project came from my own brain.

Since I work for a company that sells its software products and turns a profit doing so, I am very leery of using code created by others, I would much rather rework a concept in my own code. I have encountered a few situations where there was only one way of doing something in code the way I wanted it done, but if that is the case, then in my mind that would be difficult if impossible to copyright.


Actually there's an interesting issue at work with a University assignment. Most universities require that you sign over the rights to everything you work on while there to the university so if you don't have legal rights to the code you probably can't legally submit it to your professor. So it goes beyond plagerism if the profession should for some reason try to publish your work and later the university is sued for a copyright violation.

Yes, it is extremely unlikely. But the liability is all yours. Include the license or don't use the code.


How about:

  1. Read the "free" code
  2. Learn and understand how it works
  3. Write your own version that does the same thing
+2  A: 

One easy way to keep the license of the original code without cluttering up the rest of your code would be to just copy that file into your project, then strip everything you don't need out of it. That way, you keep the license at the top, so you aren't going to run afoul of any legal problems, but you aren't trying to apply the license to just one particular section of a file, which seems a bit stupid.

Greg Rogers