

A Modest Proposal for the Copy and Paste School of Code Reuse - bdfh42
http://www.codinghorror.com/blog/archives/001257.html

======
tumult
You should copy and paste code so rarely that this shouldn't be a problem. The
author of the article proves this point effectively with his snippet example;
the correct way to fade out a window in Cocoa is with an NSAnimation and the
NSViewAnimationFadeOutEffect on an NSWindow. His code blocks the thread
directly and could cause problems, especially if called from a routine that
responds to an IBAction (GUI event).

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.

~~~
teej
Copy, paste, and modify is one of the ways I managed to learn web development
in the first place. Sometimes, understanding doesn't come from reading alone.
You need to feel the clay in your hands to mold it into the pot you want to
make.

~~~
gnaritas
Ever think that it actually slows your learning down? Honestly, you learn code
much better if you actually type it yourself. Even if you have a working
example, retype it manually, it'll make you appreciate doing proper reuse via
function calls much better. Copy and paste is a bad habit, code is not clay,
and treating it as such hurts you.

~~~
teej
I'm not saying I do this today, I'm saying it was integral to my learning
process when I started, years ago. Typing it out doesn't help solve the issues
of learning the subtleties of syntax. You need to start with something that
works and then start seeing the ways your poor typing breaks the code.

------
vinutheraj
Err .. I am the only one with this view or did anyone else also think that the
article wasn't provided any new insight or point of view. He just basically
iterated everything that everyone knows about the pros and cons of copying
code ?!

~~~
anthonyrubin
That is what Jeff does. I really don't understand how every one of his inane
posts makes the front page of HN.

------
snprbob86
There already is a globally unique identifier, although not necessarily a
"GUID", on things you get from the web:

It's called a URL.

------
biotech
If one had a database of code snippets, then, given a specific code snippet it
would be possible to find "similar" code in the database: code that had been
changed or improved from some original version. One could even create an
evolutionary tree for each snippet, if one were so inclined.

The pertinent algorithms are already in heavy use in bioinformatics.

------
patio11
If there were only some way to give code snippets on the web some form of
universal resource locator, you could skip the guid...

~~~
varaon
The existing problem (for Jeff) is that it is hard to find modified or
improved versions of the same snippet. Whereas a URL points to an inidividual
snippet, the GUID could point to different versions. The same GUID could also
be used for the same snippet in a different language.

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.

~~~
mjs
But ... you can still Google for the URL.

------
zacharydanger
Jeff Atwood is essentially describing git/github.

------
silentbicycle
Finding copy-pasted pieces of code that have been modified in place is
actually a rather difficult problem. I've been working on a tool for this in
my spare time over the last several months, and I hope to release it sometime
this summer. Pinning down what's "similar enough" is subtle, and if you go too
far, it complains that boilerplate-y code in e.g. Java is unnecessarily
redundant. (While this is certainly _true_ , it's not useful.)

I look forward to the upcoming structured programming revolution. Some day,
people will _use subroutines_!

------
mannicken
Oh my god, I can almost see some noir company disabling Ctrl-C/Ctrl-V on
programmer's laptops.

------
csomar
I think it needs a system, not simply developers do it like that.

May be a new startup that takes care of snippets

~~~
pavel_lishin
Like the ones he linked to?

