Total Pageviews

Thursday, September 30, 2010

Hazards of Copy/Paste

Copy/Paste is way of coding for many. Copy/Paste can be from websites or another source within company or project. I am not talking about that.

While you write code there are many times you have to repeat some things with slight changes. What you do is simply copy/paste. These are cases that you cannot get to write as subroutine. What happens is if the slight change is required at multiple places its quite likely that you may forget at one place. One's attention is lesser while one is doing copy/paste of code than while one is writing.

Now starts the most dangerous phase. This program since it does not have syntax issues will compile nicely(or will have same syntax error at two places :-)). Well as it goes in programming world its not as much about the programming as it is about debugging. Nightmare starts once you run the program. It will result is some unexpected signature. Since the context of your debug might be totally focused on the conceptual change you have done, you might have tough time getting to the bug that creep in due to copy/paste.

Time saved during copy/paste you might end up paying in the ugly debug which will take far longer time. Unless you are highly diligent and can maintain most of the time its not worth copy/paste small chunks of the code. Better write them again. It will not only reduce silly bugs but also improve the familiarity with the language.

Say No to small copy/paste and even when you have to do pay full attention as if you are writing it fresh. You cannot take it easy, Be Alert !