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
@anto, i think i understand what the OP means. OP has grabbed some code from somewhere, wants to use it or integrate it with some work he/she is doing. my suggestion, for the OP to credibly take ownership of something obtained somewhere else is to (1) learn/understand it, (2) improve the code both functionally (refactoring) and cosmetically (better, more consistent symbol names) and (3) run it within his/her own project. i've done this with this fast (O(log2(N)) sliding max algorithm. my code is mine, but i learned the alg from somewhere else. –  robert bristow-johnson Apr 27 at 23:59

6 Answers 6

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
+1 for "metonymous" –  Mawg Apr 28 at 12:45

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
SO posts are licensed as CC-BY-SA 3.0 (scroll down to the very bottom of the page) so if somebody writes up a complete solution for your problem, you're only allowed to copy it verbatim if you mention the author and your code is published under the same license (or not published at all). But as you say, that kind of copy & paste coding is bad practice in the first place. –  5gon12eder May 17 at 11:52

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 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
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
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
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
This answer contains wrong and bad information. –  JacquesB May 18 at 9:05

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

I'd suggest that you use whatever sources you can find to figure out how to solve a problem. And once you have figured it out, you remove all these sources from the screen and write your own solution.

Unless you have a photographic memory and copy one of the existing solutions, this solves the problem of plagiarism and/or copyright infringement. It also helps you by forcing you to actually understand the problem.

You can go a slight step further: Most solutions that you find on the internet have one fault or another. Just because it's on the internet doesn't mean it's perfect. Figure out what is not quite correct and fix it. That way you get a better understanding, have better code, and definitely avoid any accusation of copyright infringement or plagiarism.

share|improve this answer

Your Answer


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