Developing software programs usually involves dealing with many common and repetitive problems. These frequently encountered issues can be often found solved elsewhere by someone else. Copying and re-using others’ solutions could easily save hours and maybe days implementing the same solution over and over again.
The majority of developers do copy code most of the time. They copy their own code or other developers’ code that can be accessed online. StackOverflow itself has captured more than 40 MILLION copy commands on its pages in only two weeks!
Nevertheless, copying others’ code snippets might be tricky and prone the entire software to unexpected faults. It could also put the developers in trouble facing legal issues due to breaking the license of the re-used code.
In this article, we discuss why developers copy/paste others’ code, when, and how often. We also check to what extent it is legal to copy code from common platforms such as StackOverflow and GitHub.
1. Do Developers Copy and Paste Code?
Regardless of their purposes and complexity, all computer programs consist of many small and self-contained code snippets. Each of these aims at solving a specific programmatic problem while providing a part of the final solution.
In most cases, there will be a very high chance these smaller problems have already been encountered before. They perhaps have been also solved by other programmers in many different contexts.
That said, many programmers can benefit from the code that others write to help them solve similar issues. In this context, do developers actually copy code when developing their projects?
Certainly, the majority of developers do copy code most of the time. This might be their own code that they previously produced, code from public repositories, open-source code, or most often code from StackOverflow’s answers and comments!
The key reason behind this is that most likely a solution for the same problem already exists, and sometimes two or three. Thus, it is just a waste of time reinventing the wheel by re-writing the same solution for the same issue that has been solved by someone else.
Accordingly, copying and pasting code like repetitive functions and code snippets are quite common tasks in the developer’s life.
On top of that, a useful skill of good developers would be to search for and quickly find answers to programmatic questions. And eventually, to decide which solution is the best or most applicable in their case.
2. Is It Okay to Copy Code?
Copying code snippets for common tasks usually save too much effort in recreating the solution from scratch. Nevertheless, blindly copying and pasting code without understanding the underlying solution is totally a bad practice.
In most cases, it’s totally okay for developers to copy code in their projects, providing they understand what they are copying, and the code license permits re-using it in the way intended.
Do NOT Copy the Code, Copy The Solution!
Depending on the nature of the function or script, developers should be aware of the solution they are going to reuse. This must include: understanding the problem it solves, how this code deals with it, what the advantages and disadvantages of this solution are, and which exceptions this solution might raise.
Developers do not STEAL code, they just REUSE it!
As a result, and based on all mentioned points, developers should determine if it’s okay to inherit the solution and re-use it in their program. This couldn’t happen without reading along the whole code, understanding every single instruction, and knowing how it can be modified and properly used in various contexts.
With that in mind, it will be highly important to check the code documentation (if exists) as well as all its comments and discussions.
3. How Often Do Developers Copy Code?
Although cloning others’ code is a fairly common practice in software development, the majority of the developed software is usually written from scratch. Typically, copy/paste tasks cover only common and repeatedly encountered problems.
That said, how often do developers copy and paste code?
There is no practical way to measure how often developers copy code or the proportion of the copied code in comparison to the originally created one. However, StackOverflow has captured more than 40 Million copy commands from their questions in only two weeks.
Accordingly, let us resort to some stats from the preferred source to copy code for most programmers, StackOverflow.
Based on an article on their official blog, StackOverflow installed a system that captures every time the visitor copied something from their website. The collected data covers two weeks from March 26, 2021, to April 9, 2021.
Here are some of the pretty interesting facts this experiment has revealed:
- Everyone is copying from StackOverflow!
- Visitors have performed 40.6M copy commands across 7.3M posts and comments within two weeks.
- One out of every four users who visited a question copied something within five minutes of hitting the page.
- 52.4% of copies come from answers that are not accepted.
- Most copies occurred during the working days/hours.
- Copies come from Asia 33%, Europe 30%, and North America 26%.
- 86% of all copies came from unknown users (anonymous users, not logged-in users, …).
Despite these statistics coming from only one source, they are quite sufficient to make sure that many developers/programmers copy code regularly.
4. Is Copying Code Illegal?
Although copying others’ solutions might be a collaborative practice, having access to the code doesn’t necessarily mean copying it is a fully legal thing.
With that in mind, is it legal/illegal to copy code?
Copying code is illegal if the license behind this code prevents re-using it in some way. Which is usually subject to specific contexts and under certain conditions.
The right to copy any code snippet totally depends on the license under which this code is published. This license essentially indicates if and when it’s legal to copy, modify, inherit or re-use the code in whole or in part and in which conditions.
Therefore, copying code arbitrarily and without paying attention to its license might expose you to legal issues due to violating the usage agreement or breaching the code license.
5. Is It Legal to Copy Code From StackOverflow?
StackOverflow is undoubtedly the most favorable source for developers to find solutions to their problems. StackOverflow provide a unified license for all user contributions taking place on their pages.
According to their help notice, all publicly accessible user contributions on StackOverflow, including questions and answers, are licensed under the Creative Commons Attribution-ShareAlike (CC BY-SA) license.
It is legal to copy and re-use code from StackOverflow as long as you attribute the source and use a similar license.
With that being the case, to comply with StackOverflow license terms, you need to:
- Include a link to the original answer/question in a comment in your source code (
CC BY
condition). - Maintain the same conditions/license in the copied code (
CC SA
condition).
Alternatively, you can just read the solution, understand it, and reproduce it in your enhanced version.
Nonetheless, you can still copy and modify solutions freely from StackOverflow in specific cases. Namely, if you are just copying small code snippets that don’t represent a real contribution and many other programmers can come up with them. For example, copying the code that iterates over a Dataframe in Pandas!
6. Is It Legal to Copy Code From GitHub?
GitHub is a code hosting platform to control code versioning and collaborations between multiple developers.
Contrary to StackOverflow, GitHub doesn’t impose a specific license for all user contributions. Instead, each contributor can specify the license of the shared code.
Although most code on GitHub is open-source, some repositories assign other licenses that dictate certain conditions for copying and reusing the code.
It is legal to copy code from GitHub if the licensing terms of the repository explicitly permit reusing it. If the code is open-source, then you can copy the code, modify it as you want, and reproduce it for your own purposes.
To check the license of a specific project on GitHub, there should be a file called LICENSE
, LICENSE.md
, or LICENSE.txt
next to the other project files. When clicking on this file, it displays the license content and its permissions.
7. Conclusion
Copying others’ code is a pretty common task in the life of most developers regardless of their level of experience. This could save a lot of time and effort in reproducing the same solution over and over again. However, this should be only done with respect to the licensing conditions and the context of the copied code.
In this article, we explored if developers actually copy code and why, how often they copy code, and when it’s legal to do so from different sources.
To sum up:
- The majority of developers do copy code.
- Everyone is copying from Stack Overflow.
- Copying code is legal if the code license permits re-using it.
- It is legal to copy code from StackOverflow as long as you attribute and use a similar license.
- It is legal to copy code from GitHub if its license permits you to do so.