3 ms·
Excuse me if this is a naive question but I'm kind of confused on using just a few lines of code. I know you must attribute the original creator when the licens
by almondsays 15y ago
Excuse me if this is a naive question but I'm kind of confused on using just a few lines of code. I know you must attribute the original creator when the license calls for it but where? For instance lets say I have 500 lines of code and 10 lines of borrowed code at lines 245-255. Whats best practice in that situation?
- raphman 15y agoI don't think there is a commonly agreed practice. My opinion (and what I tell my students): Independent of the specific license, I would suggest listing sources (and uses) of all external code in your LICENSE file, and at the header of each file. This makes it much easier to check for license compliance later on. Most open-source licenses require attribution but do not explicitly specify how this should be done. Example: "check_for_update() from stackoverflow.com/... (CC BY-SA)" Depending on the license of the code you are using, you might be required to mention its use in your application's documentation (e.g. BSD, CC BY). If the code is in the Public Domain or is not sophisticated enough to be protected by copyright (thin ice!), there is no need to mention it in the source code. If it is just a few lines of code, try to put it into its own function and add a short comment. This also allows you to easily remove problematical code later on. Generally, if it is just a few lines of code, dealing with the license issues is usually not worth it. For example, you can not legally mix CC BY-SA code from Stack Overflow with GPL code. I would suggest just looking at the SO solution and writing your own implementation of the algorithm (not completely safe but probably the most convenient solution).
- lnguyen 15y agoTreat it like a citation in a paper. Add comments acknowledging and saying where the code came from. If nothing else, it'll help refresh your memory on why you needed it. Also be aware of the original licensing for the code. If it's any more than attribution you'll need to determine how it affects the rest of your code and if you might need to reimplement.
- tptacek 15y agoThere's practically no difference between using 10 lines of GPL code and using a whole package. In either case: you must comply with the terms of the GPL license; your own code is now GPL'd. The exceptions to this rule aren't worth litigating. If you're not interesting in (say) GPL'ing your code to match the 10 lines you lifted, you would be better of just reimplementing those 10 lines yourself.