CV Dropoff

Challenge us to steer your career in the right direction by uploading your CV today.

Upload your CV

IT & InnovationHow can I use code snippets found on Stack Overflow?

Share this article
Bruno Lowagie
Posted byBruno Lowagie

Bruno Lowagie is a Chief Strategy Officer at ThinkFree NV, and Founder at Wil-Low BVB and iText Group NV. Bruno is also founding member of the Eurostaff Experts community.

As developers, we use code snippets, they make light of our work in solving new challenges that have already been solved by a fellow developer. But do we understand how the legality of code sharing works? I decided to find out.

A couple of months ago, I was a speaker at an open source event and I started my talk with a quick show of hands. I asked the audience the following question: “Do you know Stack Overflow?” As most of the people in the audience were developers, this silly question caused some laughter. All hands went up: “Of course! Everyone knows Stack Overflow!”

A license to code

I went on with a second question: “Do you use code snippets found on Stack Overflow?” If one hand went down, I didn’t notice it. As far as I could tell, the complete audience was kept their hands up. Stack Overflow is where you find code that solves your programming problems, so it’s only normal that you use code snippets that are kindly provided by your fellow-developers.

But then I hit my audience with a third question: “Who knows under which license you can use the code you copy from Stack Overflow?” I sensed some hesitation. Most hands went down, but not all, so I continued and said: “If I’d pick a random person who has his or her hand up right now, and if I ask for the license that is used on Stack Overflow, will I get the correct answer?”

Suddenly all hands went down. Nobody wanted to risk giving the wrong answer, although it wouldn’t have been an embarrassment if someone had answered: “It’s complicated.” Developers usually don’t like reading fine print (does anyone like reading fine print?), and in the case of Stack Overflow, there has been some confusion about how developers can legally use code snippets shared on Stack Overflow in their source code. Let’s look at how the source code can be legally used.

Share, adapt, attribute, and share alike

Stack Overflow is part of the Stack Exchange Network, and article 3 of the Terms of Service states that “You agree that all Subscriber Content that You contribute to the Network is perpetually and irrevocably licensed to Stack Exchange under the Creative Commons Attribution - Share Alike license v3.0.” See http://stackexchange.com/legal and https://creativecommons.org/licenses/by-sa/3.0/

What does that mean?

If a developer posts code on Stack Overflow, that “licensor” accepts the Creative Commons license that allows you to share and adapt that content:

  • Share: copy and redistribute the material in any medium or format,
  • Adapt: remix, transform, and build upon the material for any purpose, even commercially.

The licensor cannot revoke these freedoms as long as you, the user of the content, follow the license terms. In the case of the “Attribution - Share Alike” (CC-BY-SA v3.0) license, these terms are:

  • Attribution: you must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable matter, but not in any way that suggests that the licensor endorses you or your use.
  • Share Alike: if you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.

The Stack Exchange Network interprets ‘attribution’ in a fantastically complicated way, written in legalese that even educated people have trouble parsing, let alone fully understanding. The Share Alike part isn’t trivial either. While the CC-BY-SA works well for some communities on Stack Exchange – for instance, it works well if you want to share a recipe for Eggs Benedict found on cooking.stackexchange.com – it doesn’t work well for Stack Overflow because source code is involved.

The Creative Commons, not a software license

The Creative Commons FAQ recommends against using Creative Commons licenses for software. Instead, they strongly encourage to use one of the very good free / open source software licenses which were already available.*

Source code is a challenging issue, because CC licenses do not contain specific terms about the distribution of source code. To make matters more complicated, Intellectual Property is often involved with software and the licenses may not be compatible.  For example, the below in an excerpt from the Creative Commons FAQ:

 “Unlike software-specific licenses, CC licenses do not contain specific terms about the distribution of source code, which is often important to ensure the free reuse and modifiability of software. Many software licenses also address patent rights, which are important to software but may not be applicable to other copyrightable works. Additionally, our licenses are currently not compatible with the major software licenses, so it would be difficult to integrate CC-licensed work with other free software.”

Knowing that no hand was raised after I confronted my audience of developers with the question “Who knows under which license you can use the code you copy from Stack Overflow?”, I assume that many people have been using code found on Stack Overflow in a way that is in violation of the Terms of Service on Stack Overflow. They underestimate the potentially viral nature of the CC-BY-SA.

Some developers argue that they count on the concept of “Fair Use”. It is often accepted that copying trivial code is considered “Fair Use,” in which case you don’t have to follow the terms of the CC-BY-SA. There’s a problem with this “escape route”: how do we decide whether code is trivial? Some companies define “trivial” as copying only ten lines of code, or less. This is particularly tricky in an international context. In the US, the legal doctrine of Fair Use doesn’t apply to embedding excerpts of copyrighted works into source code. You can rewrite “ideas” that are expressed through a source code snippet, but you cannot copy snippets of code via Fair Use, regardless of the number of lines you are copying. If you do, you are violating the original work’s copyright. Another workaround is to adapt the code beyond recognition, but that’s not always possible. Changing variable names and keeping the code structure is a transparent ruse.

Plans to fix this problem were proposed by Stack Overflow in December 2015. The idea was to keep the textual part of the answers CC-BY-SA v3.0 but to make the code available under the MIT license. There was a massive protest against this proposal because the MIT license is just too permissive for many people who provide quality answers. The proposal didn’t make it; code on Stack Overflow is still licensed CC-BY-SA v3.0.**

Java Software Engineer? Take our HackerRank challenge and use your score to advance your career (or just to boast to your colleagues).

Eurostaff Connect Sweden. Join our community to network, share ideas, collaborate, create opportunity and have fun!

Eurostaff Connect Belgium. Join our community to network, share ideas, collaborate, create opportunity and have fun!

Eurostaff Connect UK. Join our community to network, share ideas, collaborate, create opportunity and have fun!

C++ Software Engineer? Take our HackerRank challenge and use your score to advance your career (or just to boast to your colleagues).

Devops Engineer (Chef)? Take our HackerRank challenge and use your score to advance your career (or just to boast to your colleagues).

Android Developer? Take our HackerRank challenge and use your score to advance your career (or just to boast to your colleagues).

We offer a competitive referral scheme for individuals referred to us. Get in touch to see how you could benefit from simply sending some details!

Java Software Engineer in France? Take our HackerRank challenge and use your score to advance your career (or just to boast to your colleagues).

Would you give up your existing car for an autonomous one?


© Copyright Eurostaff / Site designed and developed by Venn Digital

Video Test