47

As part of our research, we've reconstructed and analyzed the evolution of Stack Overflow posts. In the course of that research, I extracted clones of code blocks from the official Stack Exchange data dump released 2018-09-05 and built a small website listing clones with at least 20 lines of code that are present in at least 20 different Stack Overflow threads.

I qualitatively analyzed the top 50 clones in that list and was able to identify the source (or at least a source) of the snippets in most of the cases. Moreover, I checked if the Stack Overflow posts refer to each other, which was rarely the case. In one example, a Java snippet was found in 45 different Stack Overflow threads and could have been copied from this website. It is not clear if this external source or this Stack Overflow post is the original source of the snippet. The post on androidhive was created around May 2012, the first occurrence on Stack Overflow was mid April 2012. Assuming that androidhive is the original source, the usage on Stack Overflow could be problematic (see their terms of service). If the original source is Stack Overflow, the androidhive author did not adhere to Stack Overflow's CC BY-SA license. I identified four more variants of this snippet on Stack Overflow (1, 2, 3, 4).

Another example is this VBA script, used in 21 different Stack Overflow posts and copied from here. The first occurrence attributes this source, but I didn't find any indication on the linked website that redistribution of that snippet is allowed.

I don't want to discuss when a snippet is copyrightable here, because there are already discussions and blog posts on that topic (1, 2, 3, 4). I also don't want to discuss the usage of code snippets from Stack Overflow on other platforms (I conducted research on that, too). What I want to discuss are the following two problems:

  1. Duplicates of (non-trivial) code snippets within Stack Overflow:

    The duplicates within Stack Overflow could indicate that different threads solved a similar problem. However, if there is no link between those threads, the information is spread and hard to capture for readers. Would it make sense to point Stack Overflow users to related threads based on the similarity of the code blocks posted in a thread? This could be done before users post a question or integrated into the website for existing posts.

    EDIT: This snippet is present in 31 different posts, most of them created by the same author. I suggested an edit pointing from a later answer to the original post, but the author of the snippet rejected the edit. I would appreciate your feedback on this matter. Is copying the same snippet into different answers really considered best practice? Wouldn't it be better to just point to the original post? That way, only one snippet needs to be kept up-to-date (bug fixes, improvements, etc.).

  2. Duplicates of (non-trivial) code snippets copied from external sources into Stack Overflow:

    In the example above, the (possible) external source had a strict policy regarding the reuse of content. However, I also found copies of code snippets from the official Android documentation on Stack Overflow (example), which is licensed under CC BY 2.5, requiring attribution. Since I found many posts not referring to the source of the snippet, even those duplicates could be problematic. Leaving the copyright and licensing issues aside, Stack Overflow recommends to "always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline". But does it really make sense to copy such a code snippet (at least 14 times) from the Android reference documentation into Stack Overflow posts?

    EDIT: I suggested edits adding the missing attribution for three posts using the above-mentioned Android snippet (1, 2, 3).

I'm aware that non-trivial is a vague description, I just wanted to make clear that I'm not talking about short inline snippets, but whole code blocks of a certain size. Obviously, those code blocks may contain log files, config files, or simple examples, but my list also contains enough example of Java, PHP, or VBA scripts like the ones mentioned above.

18
  • 2
    Looking at a few random result, a lot of these duplicates seem to be copies of default config files or libraries. Some of them aren't attributed, some are.
    – Cerbrus
    Oct 25, 2018 at 10:32
  • 1
    That's what I mentioned in the last sentence of my question. But there are also enough examples of actual code snippets.
    – sbaltes
    Oct 25, 2018 at 10:36
  • 15
    I see this a lot in Java (especially Android) code when researching serial plagiarists. There is a lot of example code floating around that is free to copy, but there seems to be an endemic culture that sees copying as a legitimate method of developing software. :-(
    – Martijn Pieters Mod
    Oct 25, 2018 at 11:08
  • 4
    And I am always happy to come down on accounts that regularly copy from other sources that a) do not provide adequate attribution, including clearly marking the quoted section) and / or b) where the post primarily consists of copied materials, answers should primarily be your own work, not someone else's.
    – Martijn Pieters Mod
    Oct 25, 2018 at 11:11
  • 14
    Last but not least, if you have good tools to build these connections and overviews, I suspect that the Guttenberg bot developers would like to hear about those to help catch these cases earlier.
    – Martijn Pieters Mod
    Oct 25, 2018 at 11:13
  • 2
    Thanks for the pointer! I just commented on two issues in the Guttenberg project and made them aware of our approach.
    – sbaltes
    Oct 25, 2018 at 11:59
  • 1
    If you intentionally go look for possible plagiarism then you'll no doubt find it. The standard case is somebody having used code from a book or webpage in his own project, then years later encountering an SO question that tries to solve the same problem. Make this tool useful by editing in the missing attribution. Oct 25, 2018 at 14:20
  • 4
    What kind of edits do you propose? Pointing to the external source(s)? Pointing to the first Stack Overflow post containing the snippet? In case of CC BY, I'm not even sure if it's enough to add the missing attribution, because I don't know if you can redistribute CC BY 2.5 licensed content under a CC BY-SA license.
    – sbaltes
    Oct 25, 2018 at 14:35
  • Your link does not work: empirical-software.engineering/blog/so-snippets-in-gh-projects
    – JonH
    Oct 26, 2018 at 17:05
  • 3
    @JonH It works for me
    – TylerH
    Oct 26, 2018 at 17:21
  • 1
    @sbaltes cc-by allows you to distribute the content under any license, including full copyright, if attribution is given. cc-by-sa requires someone to use the exact same license when using it elsewhere. In other words: You can distribute cc-by content under cc-by-sa, but not the other way around.
    – Sumurai8
    Oct 26, 2018 at 18:06
  • @JonH I double-checked the links and didn't find a broken one.
    – sbaltes
    Oct 26, 2018 at 18:27
  • 1
    @Sumurai8 Okay, this means that for the CC BY licensed snippets, editing the posts to add the missing attribution solves the licensing issue. This is obviously not the case for snippets licensed under a more restrictive license...
    – sbaltes
    Oct 26, 2018 at 18:35
  • What about the clones within Stack Overflow? Does it make sense to link from the newer posts to the first occurrence of the snippet? Look, for example, at the Android snippet mentioned in my question: research.sbaltes.com/so-clones/…
    – sbaltes
    Oct 26, 2018 at 18:51
  • 1
    So if I downvote all 15 answers on that use this downvote worthy code, do I get flagged for serial downvoting the user who copied and pasted it into 15 different questions?
    – Comintern
    Feb 28, 2019 at 22:31

0

You must log in to answer this question.

Browse other questions tagged .