Repetitive Tasks or Variations of A Task
One of the most harmful forms of copy-and-paste programming occurs in code that performs a repetitive task, or variations of the same basic task depending on some variable. Each instance is copied from above and pasted in again, with minor modifications. Harmful effects include:
- The copy and paste approach often leads to large methods (a bad code smell).
- Each instance creates a code duplicate, with all the problems discussed in prior sections, but with a much greater scope. Scores of duplications are common; hundreds are possible. Bug fixes, in particular, become very difficult and costly in such code.
- Such code also suffers from significant readability issues, due to the difficulty of discerning exactly what differs between each repetition. This has a direct impact on the risks and costs of revising the code.
- The procedural programming model strongly discourages the copy-and-paste approach to repetitive tasks. Under a procedural model, a preferred approach to repetitive tasks is to create a function or subroutine that performs a single pass through the task; this subroutine is then called by the parent routine, either repetitively or better yet, with some form of looping structure. Such code is termed "well decomposed", and is recommended as being easier to read and more readily extensible.
- The general rule of thumb applicable to this case is "don't repeat yourself".
Read more about this topic: Copy And Paste Programming, Duplication
Famous quotes containing the words repetitive, tasks, variations and/or task:
“Psychobabble is ... a set of repetitive verbal formalities that kills off the very spontaneity, candor, and understanding it pretends to promote. Its an idiom that reduces psychological insight to a collection of standardized observations, that provides a frozen lexicon to deal with an infinite variety of problems.”
—Richard Dean Rosen (b. 1949)
“Everything I do is done within sight of the Führer, so that my faults or mistakes are never hidden from him. I do my very utmost to live and act in such a manner that the Führer should remain satisfied with me; I am hard-working; but whether I shall always be able to cope with the tasks entrusted to me in the future as well, is an open question.”
—Martin Bormann (19001945)
“I may be able to spot arrowheads on the desert but a refrigerator is a jungle in which I am easily lost. My wife, however, will unerringly point out that the cheese or the leftover roast is hiding right in front of my eyes. Hundreds of such experiences convince me that men and women often inhabit quite different visual worlds. These are differences which cannot be attributed to variations in visual acuity. Man and women simply have learned to use their eyes in very different ways.”
—Edward T. Hall (b. 1914)
“The really efficient laborer will be found not to crowd his day with work, but will saunter to his task surrounded by a wide halo of ease and leisure.”
—Henry David Thoreau (18171862)