AntiPattern Name: Cut-and-Paste Programming
Also Known As: Clipboard Coding, Software Cloning, Software Propagation
Most Applicable Scale: Application
Refactored Solution Name: Black Box Reuse
Refactored Solution Type: Software
Root Causes: Sloth
Unbalanced Forces: Management of Resources, Technology Transfer
“Hey, I thought you fixed that bug already, so why is it doing this again?” “Man, you guys work fast. Over 400,000 lines of code in three weeks is outstanding progress!”
Cut-and-Paste Programming is a very common, but degenerate form of software reuse which creates maintenance nightmares. It comes from the notion that it’s easier to modify existing software than program from scratch. This is usually true and represents good software instincts. However, the technique can be easily over used.
This AntiPattern is identified by the presence of several similar segments of code interspersed throughout the software project. Usually, the project contains many programmers who are learning how to develop software by following the examples of more experienced developers.
However, they are learning by modifying code that has been proven to work in similar situations, and potentially customizing it to support new data types or slightly customized behavior. This creates code duplication, which may have positive short-term consequences such as boosting line count metrics, which may be used in performance evaluations.
Furthermore, it’s easy to extend the code as the developer has full control over the code used in his or her application and can quickly meet short-term modifications to satisfy new requirements.
Symptoms And Consequences
The same software bug reoccurs throughout software despite many local fixes.
Lines of code increase without adding to overall productivity.
and inspections are needlessly extended.
It becomes difficult to locate and fix all instances of a particular mistake.
Code is considered self-documenting.
Code can be reused with a minimum of effort.
This AntiPattern leads to excessive software maintenance costs.
Software defects are replicated through the system.
Reusable assets are not converted into an easily reusable and documented form.
Developers create multiple unique fixes for bugs with no method of resolving the variations into a standard fix.
Cut-and-Paste Programming form of reuse deceptively inflates the number of lines of code developed without the expected reduction in maintenance costs associated with other forms of reuse.
It takes a great deal of effort to create reusable code, and organization emphasizes short-term payoff more than long-term investment.
The context or intent behind a software module is not preserved along with the code.
The organization does not advocate or reward reusable components, and development speed overshadows all other evaluation factors.
There is a lack of abstraction among developers, often accompanied by a poor understanding of inheritance, composition, and other development strategies.
The organization insists that code must be a perfect match to the new task to allow it to be reused. Code is duplicated to address perceived inadequacies in meeting what is thought to be a unique problem set.
Reusable components, once created, are not sufficiently documented or made readily available to developers.
A “not-invented-here” syndrome is in operation in the development environment.