18

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?

3
  • 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, 2011 at 20:23
  • 1
    @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. Apr 27, 2015 at 23:59
  • While I understand the question to be broader, this link may be relevant: Can I legally use code I found on a forum?
    – John Wu
    Oct 12, 2018 at 21:28

5 Answers 5

30

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)
0
4

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

1
  • 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, 2015 at 11:52
4

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.

1

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.

0

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).