Click Now!
a>
Like me? Like YOU! Get FREE Likes, Fans, Followers, Tweets

Wednesday, 1 January 2014

Computer Programming

Learn More About Copy-Paste Programming When programmers are in a hurry to get work done, they sometimes practice ‘copy-paste programming’. In this column, we take a closer look at the consequences of this practice. A widely known secret among programmers, who are under pressure to be ‘productive’ and churn out hundreds and thousands of lines of code every day, is to make extensive use of two commands: Ctrl+C and Ctrl+V! So just how much code is duplicated in real world software? We don’t know about closed source software, but for open source software, a study showed that 8.7 per cent of GCC, 19 per cent of X Windows, 22.7 per cent of Linux and 29 per cent of JDK consisted of duplicate code! For any seasoned programmer, these numbers are not at all a surprise. So, instead of talking about why code duplication occurs, let’s discuss the impact or consequences of copy-paste programming. Before that, let us briefly go over the kind of code duplicates (a.k.a. code clones) that abound. Type 1 clones: An exact copy without modifications, except for white spaces, new lines and comments. Type 2 clone: Syntactically identical copy, with only variable, type or function names changed. Type 3 clone: A copy with modifications, such as statements changed, added or removed. Apart from these three types of clones, we also have a fourth kind: code segments that semantically do the same thing, but are syntactically different. These clones cannot be detected automatically by clone analysers, but need to be found manually. A common mistake while copying code is that programmers copy code, but forget to make the relevant changes necessary for the copied code to be used in the context into which it has been copied. For this reason, Type 1 and Type 2 clones can result in bugs.

No comments:

Post a Comment