Register / Log in

epic fail pictures
see more Epic Fails

Okay, normally I try to steer away from echoing the mindlessness of the internet here, but this seemed appropriate. It also made me think – yeah, developers are definitely vulnerable to this.

I suppose the upside is that usually our copy-paste mistakes rarely get seen by the real world, as they normally break the build, forcing us to correct them. Sometimes copying large chunks of code really is the most efficient method to get a lot of code written quickly. However, you usually want it to do something just a little bit different. The results can be show stopping when you forget to update a specific variable of function call.

Copy & paste can be a developers best friend, or worst nightmare. I can speak from experience in that they’ve helped me save a lot of time and caused me to waste a lot of time. When I copy large chunks of code in which small sections need to be replaced, here are a few personal things I do:

  1. Generally rely on ‘find and replace all – in selection’ as opposed to relying on my own eyes.
  2. If I know that a particular variable is what will be changed, I’ll replace it with something unique, such as ‘!!!’, which will then allow me to make use of ‘find and replace all’. It will also guarantee that my code won’t run until I’ve attended to all instances of !!!. The alternative is that, potentially, the code could compile and run using the wrong variable. For multiple variables I’ll use !!!a !!!b !!c etc..
  3. For large blocks of code, open a new text file and do all of my work in that ‘scratch space’ before copying the resulting chunk back into my main program. This just makes is easy for me to mentally focus on what I’m doing, as well as say “okay, I totally messed this up – close without saving or delete all, I’ll start over“.
  4. If I’m running into a problem that I’m pretty certain is related to copy-paste and I just can’t find it, I might just work on something else or take a break all together. It’s like writing, in that immediately after you’ve written it you see it the way you expect it to be as opposed to the way it really is. Step away and give you mind some time to forget it a little, then come back and review it. You’ll notice things that you didn’t before.
View Comments

blog comments powered by Disqus