Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Copy-and-paste programming
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Repetitive tasks or variations of a task === [[File:Forgotten edits in copypaste programming.gif|thumbnail|Difficulty and risk of maintaining code written by copy-paste programming]] 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.<ref>{{ cite web | url=https://www.maansoftwares.com/blog/development/coding-standards-β-way-maintainable-code | title=Coding Standards β The Way to Maintainable Code | publisher=MAAN Softwares INC. | author=Ashley Marsh | accessdate=2018-04-10 }}</ref> * 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.<ref>{{cite web|url=http://www.stanford.edu/class/cs106x/handouts/14-Decomposition.pdf |title=Stanford University, CS 106X ("Programming Abstractions") Course Handout: "Decomposition" |publisher=Stanford University |accessdate=2008-06-04 |url-status=dead |archiveurl=https://web.archive.org/web/20080516005005/http://www.stanford.edu/class/cs106x/handouts/14-Decomposition.pdf |archivedate=May 16, 2008 }}</ref> * The general [[rule of thumb]] applicable to this case is "[[don't repeat yourself]]".
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)