Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I understand plagiarism and paraphrasing fairly well when it comes to writing a research paper, but those equivalent areas in programming seem foreign to me. I've looked up the topics online, and surprisingly there is not as much material on the subject as one would have expected.

When writing code and having to implement something I've never implemented before, I'll go online to look for an example. I try to read through the documentation beforehand, but sometimes I find it challenging to follow. So if that fails, I will search for the topic online and be presented with dozens of examples (whether they be on someone's personal blog or a Q&A site like SO). Now I'm usually presented with 5-10 lines of code. I have and will NEVER copy-and-paste that into my own code, but I still worry about copying it down verbatim. I find it hard to reword a certain piece of code, especially when there are only so many ways to do so. I make sure to rename variables, change formatting, etc. - but is this enough?

I've always wanted to understand this topic, but now that I'm working with a new language and in a corporate environment I think that it is especially pertinent. If anyone could explain or link to a good explanation elsewhere, I would greatly appreciate that!

tl;dr I don't understand how much you have to change and reword 5-10 snippets of code found online to avoid plagiarism. What if there is very little that you can change?

share|improve this question

migrated from stackoverflow.com May 29 '11 at 18:55

This question came from our site for professional and enthusiast programmers.

    
If you have to actively think about avoiding plagiarism, something is wrong with the system. Sure, you should never just copy something, but it shouldn't have to think about it. –  Anto May 29 '11 at 20:23

5 Answers 5

Plagiarism is not the same as copyright infringement. Plagiarism is passing off someone else's work as your own. It is possible to commit copyright infringement without plagiarizing:

// The following code is lifted, without permission, from Windows 2000.
// Copyright © 2000 Company-metonymous-with-Redmond.
// ...

and it's possible to commit plagiarism without copyright infringement:

/* I wrote this function. */
int sqlite3Strlen30(const char *z){
  const char *z2 = z;
  if( z==0 ) return 0;
  while( *z2 ){ z2++; }
  return 0x3fffffff & (int)(z2 - z);
}

(lifted from a public domain serverless SQL database engine)

To avoid plagiarism, you could consider citing your source. Here's an example (of which there are many) from PostgreSQL:

/* datebsearch()
 * Binary search -- from Knuth (6.2.1) Algorithm B.  Special case like this
 * is WAY faster than the generic bsearch().
 */
static const datetkn *
datebsearch(const char *key, const datetkn *base, int nel)
share|improve this answer

If you change and reword code only to avoid plagiarism, you only (try to) avoid detection of plagiarism. It all depends on what piece of code you copy. One possibility is to value a given code snippet as just a helpful guide with limited creative originality or as common practice that nobody can claim authorship. The other possibility is to value it important enough to give credit. You can give credit on several levels, from a simple code comment to making your code an official fork/branch of the original code. In summary its less about what you can do but about how original you consider the code and how you give credit if needed. Plagiarism is not copying but copying but about copying without giving credit.

share|improve this answer

Programmers generally don't worry about plagiarism the way that writers do.

If example code is openly posted on the web, it's pretty much open source and if you use it in your code (even cut/pasted verbatim), it's pretty much fair use. If you're very concerned, you could find out what open source software license is attached to the code and read the fine print. For example, any code samples you find on this site are licensed under Creative Commons and are fair play to cut paste into your own programs. Many bloggers won't even bother attaching a license agreement to the code that appears in their blogs. If you're still very concerned you could contact the blogger and request permission to use their code snippet. Personally, I wouldn't even bother. BTW: everything I've mentioned above only applies to open source code found on the web. I definitely wouldn't treat closed source code this way e.g. code you might find within a company you work for.

share|improve this answer
4  
If they don't "bother attaching a license agreement", it doesn't mean that the code is open source. It means that you do not have a license to use it. On the other hand, I doubt they are going to (want or be able to) restrict your usage of code they post on their blog, so practically speaking this doesn't pose a problem. –  Rein Henrichs May 29 '11 at 19:10
6  
Really bad advice. The world wide web is not a public-domain playground. As Rein says, code without a license attached means the exact opposite of what this post says; it has an implicit copyright and you are not allowed to use it or any derivative works, not even with attribution. Code-sharing sites either have licenses that apply to all code on the site, like the CodeProject license or work like CodePlex and allow/require authors to specify a license when they post code. –  Aaronaught May 29 '11 at 20:40
1  
On the other hand a 5 line snippet to do a common task in a given language may be the only/obvious way to do the task, and just posting it on a blog does not grant anyone copyright on it, –  Andrea May 29 '11 at 23:05

Using tutors/tutorials is not plagiarism. If I were to copy someone else's answer here, that would be plagiarism. If I linked to it, showing a quote, that wouldn't be plagiarism.

Check that your source allows the (re)use (license, written permission). I think (need to check) anything on SO will implicitly be pub domain (or creative commons, share alike etc) or it wouldn't really be able to work. (What use is getting an answer you know you can't use)

In short I feel that maybe you don't understand plagiarism all that well, unless the definitions differ wildly in the field of academics?

My rule of thumb: use all answers that merely accelerate the results you were getting anyway. However, if you find a sample that magically works but you really don't know how (or why) you're crossing the ethics line.

On the subject of modifying small snippets I'd argue the inverse; how would you integrate small snippets into your code without reorganizing : the chances that it would fit in are pretty slim and I have a pretty strong opinion on what my code should look like. Maybe you lack that 'opinion' (read: experience) and I suggest writing more code to gain confidence. Another technique to gain experience is to read an answer, and then go and apply it without accessing any sample code. You will make mistakes, but you will also learn enough to

  • reproduce it the next time
  • get confidence as to whether you understand the code
  • feel good about yourself

sent from my HTC; please indulge a typo or two

share|improve this answer

If you're not coding in an academic environment, why would you worry about plagiarism? In a professional environment, it only matters if you plagiarize other employees in your company. Plagiarism is about who gets credit. In any event, the solution to plagiarism is simple -- anything you take, give credit to the original author. If it was from a web page, include the URL. This benefits you, because if you have any questions, you may be able to find the original source again.

If your question is really about copyright infringement, remember that copyright doesn't cover functional aspects. It only covers creative choices where there are very large number of equally-useful choices. If you can't easily change the code without breaking the functionality, then it's not something copyright covers (under the merger or scènes à faire rule).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.