I've been a zone leader with DZone since 2008, and I'm crazy about community. Every day I get to work with the best that JavaScript, HTML5, Android and iOS has to offer, creating apps that truly make at difference, as principal front-end architect at Avego. James is a DZone Zone Leader and has posted 639 posts at DZone. You can read more from them at their website. View Full User Profile

Where Did That Code Snippet Come From?

04.18.2008
| 7529 views |
  • submit to reddit

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?

 

Tags:

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

passing around code is of more benefit to everyone in the long term. Its a kind of liqudity in the software world. The business would probably grind to a halt if we had to write everything from scratch in an original manner. I've never come across a code snippet that seems to be something proprietory - they are inevitably utility functions or answers to common tasks. I don't believe many of us would take our employees "widget painting" module and copy wholesale it else where. We do tend to keep old work as an aide memoir to solving past problems. Also on nearly every project I've completed I've always felt - wouldn't it be good if I could rewrite now I really understand the problem - and that I think is the option most of us take in the next job.

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.

john green green replied on Mon, 2009/10/26 - 3:27am

Or you write something that is pretty much identical to something nike shoes russiasomeone 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?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.