Where Did That Code Snippet Come From?
Have you ever wondered where that code snippet that saved the project (again!) came from? It's probably not a question you'd ask yourself when it's resulted in something being fixed or made to run better. But think back - there's probably a few suspicious snippets in your codebase right now.
Infoworld covered this in a recent blog entry, comparing developers code to the carpenters toolbox. They also mention the problem that this creates
These snippets are often reused unintentionally in a simple cut-and-paste operation without full knowledge of their former or current company's intellectual property (IP) policies. What's more, "the ubiquitous availability of code snippets in blogs and online tutorials poses a bigger risk to intellectual-property hygiene in a company,"
When it comes to keeping to a licence model, tools such as Protecode, which can work as an Eclipse plugin, detects, identifies logs and reports on any external content used outside of a companies defined policy.
There are other problems that exist with these imported snippets too - how maintainable are they, and are they efficient? It's easy for anyone to copy down code from a blog that claims to fix a particular issue, but you have to understand it to maintain it. You don't want to infringe any copyright laws, so you need to ensure you comply with the wishes of the original author, which can be as simple as adding in a comment above the snippet or class.
How much of the code you write is original, and how much is ripped off from some quick searches on Google? Do you have your own toolbox of code snippets? Have you hit any snags from using code snippets?
- Login or register to post comments
- 4414 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
Artur Biesiadowski replied on Sat, 2008/04/19 - 4:33am
Any idea how does it work? If I copy/paste the piece of code from the web page, changing the formatting and one or two variable names, will it discover it? What if I retype it ? (I hope it is not some spyware/keylogger which just checks for copy/paste action).
Jeroen Wenting replied on Mon, 2008/04/21 - 1:07am
Or you write something that is pretty much identical to something someone somewhere wrote before because it's the most logical way to do it.
How often is it going to detect common patterns as copyright violations?
Many tools these days can insert templated code. Voila, an IDE with built-in code snippets all of which are now suddenly "suspicious"?
Tom Lister replied on Wed, 2008/04/23 - 3:12am
Jason Alexander replied on Wed, 2008/04/23 - 8:58am
If I find a very creative solution to a common problem, I don't bother to keep copies of any of the actual code. But I do take note on the characteristics that I liked so I could recreate or make use of that same cleverness later down the road. For example, because A implemented XYZ, it enables this magical feature: noted.
Both on the web, in books, and at work I have run across configurations for third-party libraries, like hibernate, that did things I didn't know could be done. For those kinds of things, I would actually try to make my own example and apply that for myself. Then I keep the snippet I wrote. I try to keep those. However, I don't have many because it takes a lot of time to experiment with these kinds of things at home.
I once ran across several classes that had authors at the top. I searched google on the names and they appeared to be employees from a company in the same citythe creator of this application had worked at previously. The code wasn't even good and I don't know that the developer understood it well. I was pretty upset when I ran across this.