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!
== Deliberate design choice == Copy-and-paste programming is occasionally accepted as a valid programming technique. This is most commonly seen in boilerplate, such as class declarations or importing standard libraries, or in using an existing code template (with empty contents or stub functions) as a framework to fill in. Use of programming idioms and [[Design pattern (computer science)|design patterns]] are similar to copy-and-paste programming, as they also use formulaic code. In some cases, this can be expressed as a [[Snippet (programming)|snippet]], which can then be pasted in when such code is necessary, though it is often simply recalled from the programmer's mind. In other cases idioms cannot be reduced to a code template. In most cases, however, even if an idiom can be reduced to code, it will be either long enough that it is abstracted into a function or short enough that it can be keyed in directly. The [[Subtext programming language]] is a research project aimed at "decriminalizing" cut and paste. Using this language, cut and paste is the primary interaction model, and hence not considered an anti-pattern. === Example === A simple example is a for loop, which might be expressed as <syntaxhighlight lang=C inline>for (int i=0; i!=n; ++i) {}</syntaxhighlight>. Sample code using such a for-loop might be: <syntaxhighlight lang=C> void foo(int n) { for (int i=0; i!=n; ++i) { /* body */ } } </syntaxhighlight> The looping code could then have been generated by the following snippet (specifying types and variable names): <syntaxhighlight lang=c> for ($type $loop_var = 0; $loop_var != $stop; ++$loop_var) { /* body */ } </syntaxhighlight>
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)