4 ms·
How to correctly use code you didnt write
- boskonovitch 15y agogreat article.somebody once said "programming is filled with plagiarism" and i think that is absolutely true,noobs especially like to do it this way.
- pan69 15y agoHow does a licence impacts the distribution of plugins? E.g. if I write a plugin for a system (e.g. Wordpress) and I sell this plugin? Does the plugin code needs to be distributed under the same licence as the original system even though it wouldn't distribute any of the code provided by the original system? It would only call functions or inherit from classes described in the original system.
- handzhiev 15y agoThere's a lot of debate on this topic. Most people agree that plugins should also be GPL, so most are (even the commercial ones)
- raphman 15y agoNice overview of the 2010 Thesis theme debate: http://www.metafilter.com/93802/WordPress-Thesis-and-the-GPL http://www.metafilter.com/93802/WordPress-Thesis-and-the-GPL
- tzs 15y agoThere is case law that says that calling functions from something else does not make your code a derivative work of that something else. This issue arose when people started making unauthorized third party games for video game consoles that made use of code in the ROMs of those consoles. The SFLC says that calling a function does make your code a derivative work of that function's code. I've never seen any analysis from them that explains why they think the video game cases don't apply. They are a free software advocacy organization--they naturally tend to take the most free software friendly interpretation possible of law, and I think that often takes them a little past what the law actually is into what they wish it was. It would be interesting for someone to write a simple blogging system with a plugin interface that is compatible with Wordpress' plugin interface, and put it in the public domain. Then anyone making a plugin could claim that they actually wrote it for the public domain system, and that is what they are a derivative work of rather than Wordpress. It would be amusing to see what the SFLC would make of that. Something like this actually happened once, in the early '90s. Someone was distributing a secure email system that used RSA. It used RSA via the RSAREF library, which was freely distributable but not free software. The email system was distributed in source form. When you compiled it, you could compile it to use either the BSD arbitrary precision math library or GMP. Basically, the source had #if statements that selected whether it should assume the BSD library or GMP. (I believe GMP was under GPL, not LGPL, at the time). Stallman didn't like this. The author of the email system then wrote a toy arbitrary precision library that had the same interface as GMP, and that satisfied Stallman.
- jakejake 15y agoYour code can be GPL and you can sell it, the only problem is that you can't prevent other people from selling it as well (or giving it away for free). Also you don't have to provide a free download to the general public. It's just that everyone to whom you distribute your code has the right to request the source code. You don't have to provide source code to people to whom you did not distribute the software. Of course anybody that you did distribute the software is free to put the source code up for public download. There are sites that do that type of thing, I've had GPL software I've written show up on download sites and such. But if you are maintaining your software then they will often be out of date and hopefully you'll be showing up ahead of those in search engine listings for your own products. Basically if you're providing good value, you're less likely to be affected by that type of thing.
- cgs1019 15y agoI feel like this argument could be made more strongly than "You shouldn't copy code without the license because...don't copy code without the license!" I under-appreciated licenses for a very long time and only recently realized the very real risk of writing some code, posting it to github without any licensing, it being picked up by some commercial organization, and then them licensing it and (possibly, later) taking action against you for using their code without a license (ha!). Anyway, I appreciate the spirit of the post, but it didn't make much of an argument... Edit: I guess he also argues that it might upset the code's author to copy their code without attribution (totally possible), which would lead to their writing less open source code (seemingly less likely). I think the risk of commercialization of your code is more salient, though.
- raphman 15y agoI under-appreciated licenses for a very long time and only recently realized the very real risk of writing some code, posting it to github without any licensing, it being picked up by some commercial organization, and then them licensing it and (possibly, later) taking action against you for using their code without a license (ha!). I am not completely sure about US copyright law. However, at least in the European Union, you are the sole owner of your code as soon as you write it. Therefore, anyone putting their license on your code would be violating your author rights.
- Cushman 15y agoYou do, under the law, implicitly own the copyright to everything you create. This will not inherently protect you from costly lawsuits requiring you to prove that you do, however.
- true_religion 15y agoNothing protects you from lawsuits. I could right now sue you for slander for some comment you never made, and I fabricated evidence for. That would just make me unethical, and you can't protect against that.
- ars 15y agoPretty misleading title. I thought this was about a large project and helping people use code from other people. It should be titled: "How to correctly attribute code you didn't write"
- karamazov 15y agoSame here - I was looking forward to some advice on efficiently parsing alien coding habits.
- jakejake 15y agoI thought the article was going to be more along the lines of how to deal with people's code style, like spaces vs tabs, where the braces go, property naming conventions etc. I try to take the "when in rome" approach and if I'm messing with a class, I try to style it consistently (even though it may drive me nuts to do so)
- richbradshaw 15y agoI've found that once I've converted all the tabs to spaces, moved the { and } into the correct places, removed trailing white space, added spaces before and after operators, changed all strings to be surrounded by ' or " depending on their use case, changed comments so that // comments are on their own line, and /* */ comments are formatted neatly, I'm ready to go.
- mkramlich 15y agoYou don't happen to work for Microsoft "R&D" do you?
- almondsays 15y agoExcuse 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.
- citricsquid 15y agoIf I'm using an entire file (example from 10 mins ago: http://michelf.com/projects/php-markdown/ http://michelf.com/projects/php-markdown/) I'll leave the license in the way I find it, I have no incentive to change it. If I'm using parts of someone else's code I'll have a comment preceding it explaining where the code is from (eg: // code taken from: url). It's a massive annoyance to have to try and copy in licenses in the middle of code, it's ugly and makes reading through my code a pain. I guess I'll go to hell for it, but eh.
- deleted 15y ago[deleted]
- deleted 15y ago[deleted]
- pimentel 15y agoAt last, a simple and direct explanation of what you need to do with each license. I'm tired of answers like "just read the license and comply with it"