tags:

views:

151

answers:

3

I understand it's best to implement other libraries where possible (rather than copying code), but in some cases, it's more convenient to copy code.

What is the correct etiquette for copying code? Credit at the top of your file, near the code used? What if the code is re-factored beyond recognition?

A: 

It depends on the type of the license.

In general, the licenses want to protect the fact that they are not your work, but rather, are free for everyone. This generally entrails including the license somewhere in your project.

You can find a list of many open source licenses and their terms at: http://www.opensource.org/licenses/alphabetical

samoz
+4  A: 

The GNU GPL is very specific about how you may use the code you obtained through that license. (Be careful: If your license to the code in question is not GPL, but for example LGPL, different rules apply.) Basically GPL boils down to this:

  • If you keep the code for yourself and don't redistribute it to anybody else, you can do whatever you want with it without any obligations.
  • If you plan to share your code with somebody else, you are only allowed to do so under the GPL license. This includes that you provide the complete source code with your distribution (including your own code!), that you clearly state to the other party that this code is licensed to them under the GPL (including your own code!) and give complete information on how you altered the original code.

Even if the code is re-factored beyond recognition: If you want to distribute it, you have to follow these terms and make it understandable to the other party which parts you changed (beyond recognition ;-)). Be sure to not forget: This is not etiquette, this is copyright law!

Other licenses, such as the BSD licenses, have different terms. For example, if you use code under the BSD license, you only have to keep the copyright statement, but may happily redistribute the code under any license you like to choose, with source code or not.

ypnos
If the code is refactored "beyond recognition" then your work is no longer a derived work from the GPL code. That's conceptually identical to learning an algorithm from GPLed code and writing your own implementation. You aren't redistributing **copyrighted** GPL code, you are probably off the hook.
jhs
If it wasn't copyrighted, it would have been public domain, GPL wouldn't make sense here. I'm with you that it can become a thin line between derived work and clean re-implementation. I don't know where exactly to draw it and where the original copyright owner would indeed loose her copyright then.
ypnos
A: 

Copying code into something you're doing is legally creating a derivative work, so you must abide by the license requirements. All open source/free software licenses I've looked at demand that attribution be kept, so it's not just a question of etiquette.

If you have a list of credits somewhere, you should make sure the licensor is in that list. If it's in its own separate section (either its own file or a piece of a larger one), it'd be good to flag that and (of course) attribute it.

If it's refactored beyond recognition, it's still a derivative work, and you're still using somebody else's code, so legally and morally you must give credit.

You must of course abide by all other restrictions. You mentioned the GPL; in this case, the whole product must be redistributed under the GPL, or not redistributed at all. It doesn't matter whether the code is refactored beyond recognition and split up among files, as long as you directly used the code in your code. Different parts of the code may of course be under additional licenses, as long as they're GPL-compatible, but you must abide by the requirements of the GPL to redistribute.

David Thornley