A Modest Proposal for the Copy and Paste School of Code Reuse
codinghorror.com
codinghorror.com
There's a reason good developer documentation calls example code Listings or Illustrations: you're supposed to read and understand it, then write it yourself in your own application. Copying and pasting code verbatim is always a bad idea, even for simple things like short regexps.
Don't copy and paste code that you don't understand or couldn't write yourself.
"Don't copy and paste code that you don't understand or couldn't write yourself."
An example: you can send an XmlHttpRequest to a different port on the same domain in Firefox, but only if first you add the line
document.domain = document.domain;
Now, I wouldn't expect to be able to figure that out myself. So I just copy and paste, add a comment saying that this is a bit of magic that makes cross-port xhr's work in firefox, and add the url I got it from in the comment. Doesn't that seem reasonable?Sometimes the author is doing it as a way to ruminate on the ideas, sometimes they're doing it for some kind of ad revenue, etc.
It's called a URL.
The pertinent algorithms are already in heavy use in bioinformatics.
Obviously you could also group related snippets on a site, but that formalizes it too much. Snippets are mean to be copy/pasted and passed around on forums, blogs and sites.
I look forward to the upcoming structured programming revolution. Some day, people will use subroutines!
May be a new startup that takes care of snippets