AntiPaste, because Pasting Code Is Harmful

March 28th, 2009

A while back I proposed the idea of a Visual Studio Add-In to discourage people from copying and pasting code.  The idea got such a **great** reception, I felt honor-bound to provide a proof of concept implementation so that the guys at JetBrains would have something to start off with, when they implement this into ReSharper. 

When you attempt to paste into the Editor, Clippy appears to ask you a question:

image

 

And he won’t let you continue the operation until you affirm that yes, you have considered alternatives, or to forget about it.

 

Code is up at Google Code SVN. I know you’ll love it.

Tony Rasa

  • http://www.lovethedot.net Paul

    I love it! I need this — now I just have to figure out how to get it into our standard developer PC build.

  • http://blog.fohjin.com Mark Nijhof

    I sincerely hope that this won’t be added on my machine! When I want to move code (re-order it) I Cut and Paste. When I create a private field I copy it and paste it when I want to use it. I found this approach sometimes to work faster for me then intellicense.

    I think you are trying to fix the problem in a wrong way, what about code analysis that can discover duplicate code? I bet that this would be a performance killer but some sort of reversed diff.

    -Mark

  • http://www.arjansworld.com/2009/03/29/linkblog-for-march-29-2009/ Arjan`s World » LINKBLOG for March 29, 2009

    [...] AntiPaste, because Pasting Code Is Harmful – Tony Rasa Great idea! [...]

  • http://elegantcode.com Tony Rasa

    @Mark: actually, I’m talking to the Visual Studio Development Team at Microsoft to see if they can add a similar feature to VS2011, and so far the idea is getting a great reception.

    I’ve also been working with them to remove the letter ‘Q’ from all reserved words and keywords in C#. It’s a shifty letter – rarely travels alone, and is it an O, or a 0, or what? Can’t trust it.

  • http://www.alvinashcraft.com/2009/03/29/dew-drop-march-29-2009/ Dew Drop – March 29, 2009 | Alvin Ashcraft’s Morning Dew

    [...] AntiPaste, because Pasting Code Is Harmful (Tony Rasa) [...]

  • http://blog.cwa.me.uk/2009/03/30/the-morning-brew-317/ Reflective Perspective – Chris Alcock » The Morning Brew #317

    [...] AntiPaste, because Pasting Code Is Harmful – Tony Rasa proposes and shares the implmentation of an add on for your IDE that aims to reduce your reliance on Copy Paste development [...]

  • http://jclaes.blogspot.com Jef Claes

    Awesome.

  • http://igorbrejc.net/freshcatch/fresh-catch-for-march-30th igorbrejc.net » Fresh Catch For March 30th

    [...] AntiPaste, because Pasting Code Is Harmful | Elegant Code via the Morning Dew [...]

  • http://www.johndcook.com/blog/2009/03/30/copy-and-paste-warning/ Copy and paste warning — The Endeavour

    [...] See his post AntiPaste, because Pasting Code Is Harmful. [...]

  • http://www.onebrightlight.com Christopher Kennedy

    So wait, one shouldn’t copy and paste other people’s code. So you used the Clippy graphic from Microsoft Office? Whether or not this is a concept or a release version, it’s somewhat in the same vein, is it not?

  • http://elegantcode.com Tony Rasa

    @Christopher Clippy’s not code, so it’s ok :)

    And, see not all copy/paste is bad – that’s why you’re not strictly forbidden to do it, you only need to affirm that you understand.

    In the release version from Microsoft, the affirmation textbox won’t allow you to copy/paste the oath in either :)

  • http://www.itsananderson.com/ Will Anderson

    This is an interesting concept, and I can see what it’s trying to do, but I think it could also be a big annoyance when you’re doing a “legitimate” copy/paste action. Could there be some way of making it more intelligent so that, for example, it could only alert you if the code you’re pasting already exists elsewhere (suggesting that you need to abstract to a method)?

  • Greg

    you’d better be able to turn this off because there are times when nothing else will do — even re-factoring often involves the physical act of copying and pasting…

    In other words, I agree w/ Will A. above…

  • http://elegantcode.com Tony Rasa

    @Will: yes, the official version from Microsoft will have this feature, I’m just providing them with a prototype. The goal is to make it nearly as intelligent as the original Clippy.

    @Greg: Hmm, good point – so In production, the AntiPaste plugin will have self-defense mechanisms built in – any attempt to remove or subvert AntiPaste will result in your system drive being formatted and a mean email being sent to your mother.

  • http://www.micsaund.com micsaund

    As long as I can cut and paste that horribly long string into the dialog, it’s OK. ;)

  • http://elegantcode.com Tony Rasa

    @micsaund: don’t worry the production version will have that loophole removed ;)

  • http://csharptest.net Roger

    LMAO, I was just thinking about this on the drive into work today…

  • http://csharptest.net/?p=196 C# test.net » Oh SNAP, someone actually wrote it…

    [...] I’m just laughing my @$$ off at this one: AntiPaste, because Pasting Code Is Harmful [...]

  • Robert Höglund

    This is brilliant!

  • http://incrediblejourneysintotheknown.blogspot.com/ Daniel Earwicker

    This looks great, but as a colleague of mine has just pointed out, another thing to watch out for is when a developer makes a copy of the source directory for an entire DLL or EXE, renames it, and then adds it back into the solution. They then starts hacking away at it, almost as if a wizard just generated it for them.

    Maybe some kind of fuzzy comparison between projects would help here, to spot when they first add the new copy back into the solution.

    The dialog could say: “It looks like you’re trying to vandalize everything we hold dear.”

  • http://elegantcode.com Tony Rasa

    @Daniel Heh an excellent idea for version 2 :)

  • http://paulecoyote.wordpress.com/ Paul Evans

    Anything that slows down the coder is bad. Work in progress often means moving code around. Refactoring sometimes means moving responsibilities (and related fields and functions) around different files. Personally I would find it insulting to have to write on what amounts to lines on a virtual blackboard.

    Peer reviews on check-in, occasional code reviews… that’s where to educate a developer by means of human communication about copying and pasting code. A mechanism like this is just asking to be gamed. If forced on someone it is the equivalent of a recurring nasty sarcastic note on your screen versus an honest constructive chat.

    I understand why you might want an automated nanny like that but if there must be something like this it should be a quality gate before check-in (like fxcop / stylecop) *not* something that criticizes the work as it is being written.

  • http://elegantcode.com Tony Rasa

    @Paul It’s a joke. Lighten up.

  • http://elegantcode.com Tony Rasa

    @Paul reading that terse comment, its way more harsh than i intended. oops. so here’s a free smiley :)

blog comments powered by Disqus