Copy and paste programming

From Wikipedia, the free encyclopedia

(Redirected from Cut and paste programming)
Jump to: navigation, search

Copy and paste programming is an informal computer programming style that copies code from one program or procedure to another. It is often criticized as a bad practice or an anti-pattern. The term is in conjecture with a common activity in computing, copy and paste.

Copy and pasting is often done by inexperienced or student programmers, who find the act of writing code from scratch difficult and prefer to search for a pre-written solution or partial solution they can use as a basis for their own problem solving. The problem in this approach lies with the fact that the inexperienced programmers do not fully understand the pre-written code they are taking. As such the problem arises more from their experience, then from the act of copying and pasting, per se. The code often comes from disparate sources such as friends or co-worker's code, Internet forums, code provided by students' professors/TAs and computer science textbooks. The result risks being a disjointed clash of styles and may have superfluous code that tackles problems for which solutions are no longer required. Bugs can also easily be introduced by assumptions and design choices made in the separate sources that no longer apply when placed in a new environment.

Copy and pasting is also done by experienced programmers, who often have their own libraries of well tested, ready-to-use code snippets and generic algorithms that are easily adapted to specific tasks. However, adherents of object oriented methodologies claim that this form of programming is still wrong. Instead of making multiple, mutated copies of a generic algorithm, the algorithm should be written as a reusable class and should be written so flexibly that all new code can be interfaced to use this generic code directly, rather than mutate the original. This way, if the original algorithm has a bug to fix or can be improved, all software using it stands to benefit and the programmer does not need to hunt down each and every instance of the code (this is sometimes humorously called write-once-fix-same-bug-many-times programming).

Use of programming idioms and design patterns are distinct from copy and paste programming, as they are expected to be recalled from the programmer's mind, rather than retrieved from a code bank.

One problem with cut and paste programming is that it often doesn't preserve any semantic link between the text that is cut and pasted into various places, thus any subsequent bugs that are found have to be fixed in all places. However this can be solved if the original code, or the copy, is properly commented. There is research aimed at "decriminalizing" cut and paste, known as the Subtext programming language. Note that under this model, cut and paste is the primary model of interaction and hence not an anti-pattern.

As reaction hereof the rule "don't repeat yourself" is cited.


Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.