A Modest Proposal for the Copy and Paste School of Code Reuse

Is copying and pasting code dangerous? Should control-c and control-v be treated not as essential programming keyboard shortcuts, but registered weapons?

This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2009/04/a-modest-proposal-for-the-copy-and-paste-school-of-code-reuse.html

Jeff: add a concise method for version tracking (including branches), and then I think you’ve got something good. Without version tracking, I doubt any of the benefits of your system will hold up in the real world.

I kept waiting for the part about eating script kiddies, but it never came…

I would definitely appreciate a database of random code snippets. There are so many interesting little coding tricks and algorithms, but they’re scattered all over the internet and buried in larger applications.

A system sort of like Wonderfl (http://wonderfl.kayac.com/) would be pretty neat. They basically just have a text box on every page where you can randomly fork the code and store modifications. Other people can see the evolution of the apps through forks and revisions.

Real programmers bind copy and paste to their extra mouse buttons.


Real programmers don’t own a mouse at all… :slight_smile:

What if you copy-paste code to move it to routine of it’s own?

To nc:
I think that to copy-paste some code to make a routine of it is not bad at all, but I don’t think this is what Jeff is talking about.

I think that the most important problem with copy-paste are bad programmers, who copy-paste it without understanding what it does completely. Another problem may be the lack of consistency with the rest of code, in error tracking policies for example, or to a lesser extent, the lack of code formatting consistency.

To sum up, I think that code snippets around are better to get ideas of how to solve something rather than copy-pasting them.

Hopefully you’re cutting and pasting, not copying and pasting. Subtle distinction but there is one.

Instead of a GUID, why not use a SHA1 hash that’s based on the contents of the code snippet, like what git does?

(yes, I know that in OS X, the keyboard shortcut for cut and paste uses crazy Prince symbol key instead of control, like God intended. Any cognitive dissonance you may be experiencing right now is also intentional.)

Are you saying Apple came before God? (Well, at least the Lisa.)

I think something like http://gist.github.com/gists is a better approach. That’s what I try to do when I grab a snippet.

Legalizing copying of assignments, huh?

I agree on gist.github.com. Distributed version control is the way to go when dealing with snippets. Github gists offer version control with a low barrier, and you can easily fork snippets from other users, while the link between those snippets is maintained. Using tools that integrate with your editor, it is very easy to publish snippets.

I am amazed to see all the apple stuff here. Is the objective-c animation example on purpose? Because with core animation doing this for you how many programmers are finding this code snippet and using this. It makes a point about copy and paste programming.


Where the crazy Prince symbol key came from:

Left Ctrl+X/C/V is just a recipe for RSI btw. Right Ctrl would be better…

Why not just put the URL in the code snippet instead of GUID? Sites should be quite good at keeping URLs valid by now shouldn’t they?

I couldn’t help but notice that you included the picture of a Mac keyboard and marked the Control key…

Copying and pasting under Mac OS X is done via Command + C/V. Soo… Jeez.

This is the most retarded idea I’ve heard in my entire life.

Either that or Atwood is trolling us, AGAIN.

I like this idea, a lot.

So I expanded on it.

If you go and download the freeware tool made by Whole Tomato, the makers of Visual Assist, an addin for Visual Studio, specifically, this tool: http://www.wholetomato.com/products/sourcelinks/FogBugzBundle.asp

And then add this rule to it (Tools-Options-SourceLinks):

Name: codesnippet
Keywords: codesnippet:
(yes, add the colon)
Value: String
Url/Exe: http://www.google.com/search?q=%s

the rest as default, then the comment becomes double-clickable in Visual Studio and you’ll search for it on Google if you do.

@Mr Jay:

Copying and pasting under Mac OS X is done via Command + C/V. Soo… Jeez.

Jeff clearly outlined the irony of the picture. Anyway, the real tragedy is that the Caps Lock key is where God intended the Control key to be.

Interesting idea, i kind of like it. I don’t CP all that much, but it would be great to find a GUID i could search for when i find some arcane CP’d piece of code in an application.

I used to put the url to the snippet in a comment next to it, but sadly that solution works only as long as the page exists.

CP web snippets should of course never happen for trivial stuff, but when you are using some arcane library or extension it is often the best way to get a head start in learning how it works. Combinded with inevitable deadlines means that some of the code is bound to stay alive.

Having a GUID next to such code would be perfect to get some context when a bug arises.