This post is directed at new programmers, something that I felt like sharing as I still see friends and colleagues doing this mistake, it hurts to watch.
I’ve started coding long ago, using my old friend HTML, and I used to get pretty excited by having many lines of code, huge and complex algorithms, that no one could understand, and by the speed of what I done all that. Back then copy-paste was my biggest, and only, friend as it would speed up my work alot, or so I thought, I had no idea what intellisense was back then, not sure it even existed.
But this as all changed, the last 2 years were a infinite loop of learning how copy-paste is my worst enemy. Maybe you’re also like I was and find copy-paste, maybe along with intellisense, a good tool to speed up your programming speed but let me explain how that is just wrong.
Every time I have to copy-paste I stop, take a deep breath, and I try to figure out why I should use the copy-paste. Most of the time, maybe all of it, is the need of using that pretty piece of code that you just made and is needed elsewhere, and for that there is an easy solution, if it’s more than 3 lines long, in my opinion it is worth of it’s own function. Yes, don’t be afraid of promoting that little code to a function. If it happens to have a bug and you copied it to 3 different places you will have to go to them all and correct it, and you may forgot that you copied to a 4th place. If it’s a function it is so easy to fix it, just correct that function and it all works well.
People used to tell me this before, like I’m telling you now, and I always thought they just were being dramatic, but now that I make bigger and more complex applications I often deal with bugs on functions that if were not made a function I would spend more time copying the correct code everywhere than to actually fix the bug.
No copy-paste, along with many tests, saves you from big headaches when trying to deploy your application.