I might just be lazy, but do you ever find it tiresome to select all the source code from a large post on Stack Overflow to copy it?
I would like a feature, possibly a Firefox extension, but preferably a JavaScript script, for automatically copying source examples to the clipboard. It's no big deal for a small snippet, but a 1000+ line posting is cumbersome to copy.
Is there a better way of copying large source posts? I'm using Firefox 3.5.5 on Windows 7.
-
65Even copying 25 lines of code can be annoying sometimes. A simple "Copy" link would be really useful.Noam Gal– Noam Gal07/18/2010 14:36:41Commented Jul 18, 2010 at 14:36
-
2Cut/paste versus copy button - I'll take a copy button, hands down, for a number of reasons.IAbstract– IAbstract12/09/2010 12:57:32Commented Dec 9, 2010 at 12:57
-
Related: "Unformatting" a code block which uses a Greasemonkey script ("pre select") to copy the contents of a pre block.Arjan– Arjan12/09/2010 16:30:01Commented Dec 9, 2010 at 16:30
-
See also File attachmentsbobobobo– bobobobo12/09/2010 16:47:24Commented Dec 9, 2010 at 16:47
-
5When displaying code, it seems it's becoming more and more common on other sites to present the user with a quick option (button) that copies all the code in the code block. I don't understand the reason why stackexchange sites would not also implement this feature?mg1075– mg107507/09/2011 19:04:42Commented Jul 9, 2011 at 19:04
-
44Getting close to 2 years that this feature-request was submitted - is anyone even looking at this?IAbstract– IAbstract10/06/2011 16:18:17Commented Oct 6, 2011 at 16:18
-
On top of this, when you do finally select all and copy it, the code you paste is all unformatted and appear in one line. Is there a way to copy the formatted code with all the spacing?Jay– Jay12/14/2011 18:01:08Commented Dec 14, 2011 at 18:01
-
13It's not the copying which is a pain, it's the selecting. I've seen a "select" or "select all" button in many other sites which involve source codes, such as JavaScript minifiers and I think either or both of jsfiddle and the YQL console. Scroll-selecting sucks, and it sucks worse on a netbook )-:hippietrail– hippietrail08/12/2012 07:17:28Commented Aug 12, 2012 at 7:17
-
2So was this idea taken in consideration for future performing?fedorqui 'SO stop harming'– fedorqui 'SO stop harming'02/07/2013 09:39:13Commented Feb 7, 2013 at 9:39
-
4I love this idea! But why just one button? I've suggested a list of possible buttons: meta.stackexchange.com/questions/169119/code-block-toolsSalvatorelab– Salvatorelab02/26/2013 13:01:14Commented Feb 26, 2013 at 13:01
-
3How can we bump this feature request so it gets a final answer? I also would like to have such a button and the implementation is probably easy to do. So, why isn't it there already (after 4 years since this request came up)?Mike Lischke– Mike Lischke03/09/2014 10:18:10Commented Mar 9, 2014 at 10:18
-
3@MikeLischke "How can we bump this feature request so it gets a final answer?" It seems like there was nothing we could do to bump this feature enough. However, a final answer wasn't really needed, just not implementing the feature for many years and not putting a status on it either is also an answer I would say.NoDataDumpNoContribution– NoDataDumpNoContribution06/10/2020 10:51:42Commented Jun 10, 2020 at 10:51
-
3It has been over a decade since this question was asked. We had some pushback when I first answered back in '10. Will anyone put this thing on the ToDo list?IAbstract– IAbstract01/27/2021 22:18:05Commented Jan 27, 2021 at 22:18
-
5@IAbstract you mean over 12 years. And I bet we'll be here in 8 years as well, and it won't be done yet. ;-)user152859– user15285911/02/2022 12:59:56Commented Nov 2, 2022 at 12:59
-
1I's been 15 years. It is not surprising that SO is being overtaken by AI nowadays.Diogo– Diogo08/02/2025 22:15:14Commented Aug 2 at 22:15
23 Answers 23
I think a copy button in the corner of code blocks would be an excellent option:
a copy button above right corner in code block
A third-party browser plugin which provides similar functionality can be found at https://github.com/MrMino/StackCtrlC
Having a copy button means:
- I get all the text in the code block
- I don't have to click/drag the full length of the text
- Automatically copied to clipboard
I don't know why people would be against this small piece of added functionality. It makes sense to have a copy button. I certainly don't expect this comfort control to take priority but an official word on whether it will be considered would be nice.
Update & Alternative
I have learned that this functionality simply will not be implemented due to security concerns.
An alternative that I would not mind having would be an "Email me teh codez" button. One click, done! Now I have a somewhat permanent record of the code which I can organize in mail folders and copy at any time.
-
26I must be honest, the button is so 90's, but the idea is good.Camilo Martin– Camilo Martin02/05/2012 14:51:37Commented Feb 5, 2012 at 14:51
-
2I couldn't agree more ...but there is a certain convenience about it.IAbstract– IAbstract02/05/2012 23:09:29Commented Feb 5, 2012 at 23:09
-
3Copying code (especially long ones) from SO is a pain the ass!!!Shimmy Weitzhandler– Shimmy Weitzhandler01/01/2013 04:42:18Commented Jan 1, 2013 at 4:42
-
The button could appear only if the mouse hovers near the right-top of a code block. By the way, I'm not sure if it's technically possible to place code on the clipboard in a clean way. As I remember, you had to abuse a Flash control, which would be a no-go for any sane website.Andomar– Andomar02/07/2013 10:27:01Commented Feb 7, 2013 at 10:27
-
1ZeroClipboard seems to do a nice job of abstracting the actual "copy to clipboard" code.ThinkingStiff– ThinkingStiff02/25/2013 22:52:22Commented Feb 25, 2013 at 22:52
-
I agree with Camilo Martin lol! It's definitely possible with pure js @Andomar as Syntax Highlighter does it: code.google.com/p/syntaxhighlighterAdam B– Adam B02/26/2013 05:24:29Commented Feb 26, 2013 at 5:24
-
2FWIW, I agree. We were just having a discussion in chat.stackexchange.com/rooms/41/tex-latex-and-friends about the pros and cons of adding various plugin features. The proposer noted that latex-community.org/forum/viewtopic.php?f=37&t=22340 has them -- but it starts with the "copy" feature. In short this might open a can of worms but that could be powerful/cool.Joe Corneli– Joe Corneli03/07/2013 00:06:56Commented Mar 7, 2013 at 0:06
-
1@Shimmy: Those posts should be downvoted and then deleted.Lightness Races in Orbit– Lightness Races in Orbit07/19/2013 12:52:15Commented Jul 19, 2013 at 12:52
-
3I completely disagree. Sometimes they are useful, just not formatted the right way.Shimmy Weitzhandler– Shimmy Weitzhandler07/19/2013 15:49:17Commented Jul 19, 2013 at 15:49
-
5What kind of security concerns? Any source for that?Stijn– Stijn07/04/2014 14:11:22Commented Jul 4, 2014 at 14:11
-
4Can this be done now in 2020 atleast? Are there still security issues?Vishesh Mangla– Vishesh Mangla06/30/2020 12:25:14Commented Jun 30, 2020 at 12:25
-
6Even if there is security issue for Copy button then at least it should be no security issue to make Select All button, copying selected text ourselves is trivial.Arty– Arty01/11/2021 08:51:08Commented Jan 11, 2021 at 8:51
-
1@wim such edit is not appropriate, on the verge of spam. If you are fond of a userscript that can do what the questions asks please post new answer with it, and if your own mention it as well.user152859– user15285911/05/2024 08:10:52Commented Nov 5, 2024 at 8:10
-
1@ShadowWizard You’re wrong. My edit provides exactly what people visiting this Q&A want to find. It is too late for it to be provided in a new answer, because this is such an old question with many existing voted answers and that new information will stay buried at the bottom of page in obscurity forever. Your edit rollback is inappropriate.wim– wim11/05/2024 13:52:04Commented Nov 5, 2024 at 13:52
-
1@wim: I'm fine with an edit but at this point, expanding my answer to include yours might be more useful.IAbstract– IAbstract11/08/2024 01:35:07Commented Nov 8, 2024 at 1:35
Simple and unobtrusive. ZeroClipboard and sytaxhighlighter both seem to do a nice job of abstracting the actual "copy to clipboard" code.
small "copy" button in the bottom right corner of a code box
There are some cases in which all the code is in one line and is very long like answers to this post. These lines are hard to copy, and it would be nice to have a Copy code button.
-
CTRL+C works fine. I believe the line breaks must have been added by the original poster, because by default you will get a horizontal scrollbar instead.bobobobo– bobobobo12/09/2010 16:50:45Commented Dec 9, 2010 at 16:50
-
Why add breaks? You should be able to copy from the IDE and have the line breaks added automatically or propertly formatted or if it is no posible then the line breaks are ok. Similarly you should be able to copy code from an answer or question in an easy way.Carlos Muñoz– Carlos Muñoz12/11/2010 05:19:12Commented Dec 11, 2010 at 5:19
-
@bobobobo: CTRL+C might work fine, the issue is with the selection of the code sample block; not always easy to get right, especially with long code blocks.casperOne– casperOne08/11/2011 13:14:54Commented Aug 11, 2011 at 13:14
-
7If you're finding it difficult to select an entire line because it's so long, just triple click and it'll select the entire line.JBurace– JBurace05/30/2012 14:32:32Commented May 30, 2012 at 14:32
I don't understand people's aversion to usability. (Looking over some of the Q&A on MSO, it seems like some people have an aversion to any kind of change.)
Code snippets don't have to be 1000+ lines to create a vertical scrollbar. Worse still are code snippets on one long line with a horizontal scrollbar. Those are a real pain to copy.
How can anything that makes things a little easier be a bad thing? Today, it should be fairly simple to implement in jQuery. SE already uses jQeury anyway. I think it's worth looking into.
-
2The thing is that you would have to add the clutter of an additional UI element for relatively little gain. As long as copying code is just a bit hard (and not impossible, say, through line numbers) I'm opposed to adding thisPekka– Pekka09/16/2011 10:01:28Commented Sep 16, 2011 at 10:01
-
9But it's a fairly standard UI element for code snippits. I'd hardly call it clutter.Herbert– Herbert10/12/2011 09:01:37Commented Oct 12, 2011 at 9:01
-
5It would be no more clutter than the Share|Edit|Flag links. This is such as basic and useful feature that is very standard on many coding sites and should be there on Stack Overflow.martinjbaker– martinjbaker02/15/2013 12:48:29Commented Feb 15, 2013 at 12:48
-
1@Herbert: Changing software is not the default action. It's not a general aversion to any change -- it's that you need to present a solid use case for spending expensive man hours implementing a new software feature, and that has not been done here.Lightness Races in Orbit– Lightness Races in Orbit07/18/2013 09:24:01Commented Jul 18, 2013 at 9:24
-
Copying and pasting code out of answers is an uncommon scenario. And in the case it's not, we'd like to discourage copy-and-paste programming.Cody Gray– Cody Gray08/04/2013 10:29:31Commented Aug 4, 2013 at 10:29
-
2@LightnessRacesinOrbit I disagree about man hours, that's ridiculous. The number of man hours that were spent on less useful SO features go way beyond what it would take to add this. When a suggestion gets 148 upvotes on a meta site, and you still see some categorical yet unexplained "no"s, that's called stubbornness.Oliver– Oliver04/24/2014 05:19:40Commented Apr 24, 2014 at 5:19
-
@Schollii: Not everybody agrees with you that this should be done. "Less useful SO features" is subjective and debatable.Lightness Races in Orbit– Lightness Races in Orbit04/24/2014 09:19:10Commented Apr 24, 2014 at 9:19
I'd like to see the copy feature as well. I do more answering than questioning - and a lot of the PHP questions that I look at are written by newer users. They aren't familiar with the culture and have a tendency to post blocks of code followed by "what did I do wrong?" For these scenarios, it's often much easier to copy into an IDE and take a look at it the way I would look at my own code. (Especially if the lines extend past the codeblock width.)
SO shouldn't be a snippet site, but it is devoted to helping coders share knowledge. Such a feature facilitates that transaction.
I can't understand why people would object to taking one single click (to select all and copy) instead of many steps (as Shog9 suggested).
And w.r.t. Ether's answer, I don't think it matters how many lines of code you want to copy. I'd say it's particularly painful if there are only a few lines.
I've run into many sites with "copy code" button. phpBB has Select All.
-
2Selecting a block of text and hitting control/command-C is "painful"?Ether– Ether09/17/2010 16:22:08Commented Sep 17, 2010 at 16:22
-
7Infinitely more painful than hitting one "Copy Code" button? YES. More painful than being stuck at 11 rep? NO.Geoffrey Zheng– Geoffrey Zheng09/22/2010 14:14:28Commented Sep 22, 2010 at 14:14
I struggle with the same thing so I decided to create a browser extension that adds a copy to clipboard button on every code snippet.
It works with all Stack Exchange sites, including Stack Overflow.
If you're interested, you can use it on Chrome or Firefox.
small copy icon on the right side of a code block, circled, with the hover label "Copy to clipboard"
The source code is available on GitHub.
-
1
-
@Shub does it only function on StackOverflow?raf– raf06/23/2024 13:17:59Commented Jun 23, 2024 at 13:17
Select code block buttons.
H.B. on StackApps has written a script to do exactly this.
A user-installable script lets anyone who wants this feature have it without running afoul of any of the objections raised in other answers.
See also this question for some further discussion of similar tools.
The Stack Overflow Extras (SOX) userscript includes this feature, along with loads of other useful enhancements.
The setting is called "Add a button to code in posts to let you copy it".
Here's what it looks like:
small copy icon in the top right corner of a code block
Just click the button to save the code to your clipboard.
You'll need to install Tampermonkey (Chrome, Microsoft Edge, Safari, Opera Next, and Firefox) or Greasemonkey (Firefox) first (see above link for details).
I really would like this feature, and it would make it easy to test out code.
Like today, I wanted to copy the following:
long horizontal code block is circled, with a label "I want to copy-Paste it in Sublime 2"
-
1For single-line code: just double-click it to select-all.Alex– Alex08/12/2016 23:39:59Commented Aug 12, 2016 at 23:39
If all those "selecting" and "clipboard" functions are not possible/secure, then what about a simple link to the raw content, just like GitHub does?
Button labeled "raw" above a code block
The "raw" button links to a new page that contains the code snippet as plain text. This allows to save or copy/paste it easily.
Disclaimer: I'm no UX expert ;)
-
2By now on GitHub there is a copy button for every code chunk in the issue comments.ismirsehregal– ismirsehregal09/10/2021 13:12:58Commented Sep 10, 2021 at 13:12
The two people who said no, gave the following reasons:
- Security concern
- Ethically unpleasant
One alternative that would take care of both of them: override codeblock behaviour to select-all text within that codeblock when double-clicked.
This way, there is no additional button to be ethically unpleasant; and since you have to press CTRL+C manually, it is not a security concern.
Actually, I've created a chrome extension to solve exactly this problem. You can try it here.
Basically, whenever you double click a code snippet, it's automatically copied to your clipboard.
Do you guys have a better way of copying large source posts?
One of my primary use cases is to download C++ code directly to a file so that I can compile it and try to reproduce the problem. So I wrote this simple one-liner to download code blocks from questions:
curl -sL https://stackoverflow.com/q/11227809/72178|xmllint --html --xpath "(//pre/code)[1]/text()" - 2>/dev/null|recode html..ascii
The code block number can be specified in square brackets in an XPath expression. For me I find this more useful than a "Copy" button. Here are examples of a one-liner in action for Why is it faster to process a sorted array than an unsorted array?.
First code block:
[ ~]$ curl -sL https://stackoverflow.com/q/11227809/72178|xmllint --html --xpath "(//pre/code)[1]/text()" - 2>/dev/null|recode html..ascii
#include <algorithm>
#include <ctime>
#include <iostream>
int main()
{
// Generate data
const unsigned arraySize = 32768;
int data[arraySize];
for (unsigned c = 0; c < arraySize; ++c)
data[c] = std::rand() % 256;
// !!! With this, the next loop runs faster
std::sort(data, data + arraySize);
// Test
clock_t start = clock();
long long sum = 0;
for (unsigned i = 0; i < 100000; ++i)
{
// Primary loop
for (unsigned c = 0; c < arraySize; ++c)
{
if (data[c] >= 128)
sum += data[c];
}
}
double elapsedTime = static_cast<double>(clock() - start) / CLOCKS_PER_SEC;
std::cout << elapsedTime << std::endl;
std::cout << "sum = " << sum << std::endl;
}
Second code block:
[ ~]$ curl -sL https://stackoverflow.com/q/11227809/72178|xmllint --html --xpath "(//pre/code)[2]/text()" - 2>/dev/null|recode html..ascii
import java.util.Arrays;
import java.util.Random;
public class Main
{
public static void main(String[] args)
{
// Generate data
int arraySize = 32768;
int data[] = new int[arraySize];
Random rnd = new Random(0);
for (int c = 0; c < arraySize; ++c)
data[c] = rnd.nextInt() % 256;
// !!! With this, the next loop runs faster
Arrays.sort(data);
// Test
long start = System.nanoTime();
long sum = 0;
for (int i = 0; i < 100000; ++i)
{
// Primary loop
for (int c = 0; c < arraySize; ++c)
{
if (data[c] >= 128)
sum += data[c];
}
}
System.out.println((System.nanoTime() - start) / 1000000000.0);
System.out.println("sum = " + sum);
}
}
Considering all of the source code is wrapped around a <pre><code>
block, I suspect it would be easy enough to write a Greasemonkey snippet to find those code blocks and copy them to the clipboard for you.
Or similarly, I've been using EverNote as of late and I've found that highlighting the code in a question/answer and then hitting CTRL+ALT+V will grab the selected text and put in into a new note entry for me. Then I can easily take it where I need it.
-
5As you have stated it is easy enough. Easy enough for the dev team at stackexchange to implement it.Carlos Muñoz– Carlos Muñoz09/26/2010 18:02:08Commented Sep 26, 2010 at 18:02
-
It's not that easy, because unless you get to it before the prettyprint script, the code as a simple block of text is no longer there...Benjol– Benjol12/09/2010 13:43:45Commented Dec 9, 2010 at 13:43
-
See "Unformatting" a code block which uses a Greasemonkey script ("pre select") to copy the contents of a pre block, but shows that this needs some tweaking to get rid of the Google Prettify stuff.Arjan– Arjan12/09/2010 16:31:07Commented Dec 9, 2010 at 16:31
For now, use Click Copy {Code}. It's a Chrome extension that simplifies your workflow by copying the content of code blocks on any website with a double-click. Check out the project's source on GitHub: Click-Copy-Code.
If there is so much source code in a question that it is onerous to copy it, and especially that you feel a need to paste it all in your response, then both the questioner and you the answerer are doing things wrong. There is rarely a need for a huge amount of source, and you shouldn't have to repeat it in your response. If you do, I figure you deserve to go through a few extra steps to do so. It's not something we want to encourage.
-
17I shudder to think that he's not copying a huge block of code to paste it into a response, but into his IDE.09/17/2010 15:38:55Commented Sep 17, 2010 at 15:38
-
6I don't think the primary purpose of the copy button is to simply copy question code blocks to a response. It would be for copying code snippets to clipboard and pasted in an editor.IAbstract– IAbstract12/09/2010 13:11:25Commented Dec 9, 2010 at 13:11
- (Pick a useful web browser such as Firefox)
- Go to the code section of the post.
- Click left mouse button once at the start of the code.
- Release the mouse button. DO NOT drag the mouse cursor over the code while keeping the left mouse button pressed.
- Scroll down to end of the code using mouse scroll wheel, the page slider of the window of Page Down on your keyboard.
- Shift+click left mouse button once at the end of the code.
- Release the mouse button.
- Hit Ctrl+C on your keyboard.
- Done.
Just tried on a massive wall of code post as some sort of worse case scenario - it took me no more than 2 seconds to copy the whole code section. No add-ons or anything required.
What about something along the lines of how LaTeX-Community.org allow users to open code in writeLaTeX (an online collaborative LaTeX editor/compiler)? For details and examples of how it works, see the announcement:
http://latex-community.org/forum/viewtopic.php?f=37&t=22340
This type of integration has been proposed for TeX SX, and with the recent integration of CircuitLabs into Electronics SX, it seems like there are some precedents (and models) for how this could work.
-
I should add that I'm one of the developers at writeLaTeX, so happy to discuss how we could work on an integration along these lines for SXJohn Hammersley– John Hammersley03/07/2013 00:19:18Commented Mar 7, 2013 at 0:19
If you are struggling to select all of the code in a question/answer then the correct action is to EDIT THE POST to remove the extraneous code. There should never be so much code in a post as to pose a useability problem.
Adding auto-copy functionality will promote behemothic walls of crappy code that we simply do not want.
Nah. Jeff specifically said somewhere on his blog that SO was not for posting "huge swathes of code." And how.
What code blocks should be is 1. easy to highlight with the mouse and CTRL+C, which they are. As you can see:
Code code code
Oh more code
The other part is 2: when you paste it somewhere, annoying line numbers don't spill into your code which so far, doesn't happen.
I'd say SO has got codeblocks right, and they shouldn't be touched. I'd shudder if they ever look like the code blocks here.
I've always hated the "copy" button on sites that sites have, mostly for the reason if you can write to my clipboard, you also read it. And people don't usually like that. See the need for Flash to do this.
-
3I would hope that line numbers would not be inserted. In addition, does MSDN use flash to copy code snippets from it's site? I don't believe Flash is the only way for this to be worked out.IAbstract– IAbstract12/09/2010 17:50:02Commented Dec 9, 2010 at 17:50
-
The above example works but copying and pasting doesn't work with context colored code samples in IE8. It does work in Chrome. In IE8 the samples are pasted all in one line. See this code sample stackoverflow.com/questions/4308828/…Ed Greaves– Ed Greaves06/02/2011 14:48:07Commented Jun 2, 2011 at 14:48
-
3I actually love the code blocks you linked, shudderingly, to :)sehe– sehe07/04/2011 13:45:04Commented Jul 4, 2011 at 13:45
-
1can't find ctrl-c on my iPad... :(cormullion– cormullion08/19/2012 09:54:29Commented Aug 19, 2012 at 9:54
-
1Hold your finger down and select "Copy".bobobobo– bobobobo10/08/2012 15:07:49Commented Oct 8, 2012 at 15:07
Do you guys have better way of copying large source post?
Edit -> Select all -> Copy -> Paste -> Edit out non-source portions.
But then, the only time I'm copying 1000+ line posts is to edit them anyway. That's really a bit much for SO...
-
I want to respond this: Suggestion to implement a Copy To Clipboard button on the code snippet inclusion tag You misunderstood what I mean in my request to implement a "COPY to Clipboard" button.Display Name– Display Name12/23/2010 22:34:53Commented Dec 23, 2010 at 22:34
-
The purpose is to ease testing process when somebody answers with code inclusion. It is very useful in tex.stackexchange.com. There we intensively provide minimal code snippet for testing purpose. For the production, adjustment might be needed.Display Name– Display Name12/23/2010 22:41:57Commented Dec 23, 2010 at 22:41
-
EDIT->Select All ->Copy -> Paste will not work because if you choose Select All, the whole page get highlighted. You need to copy the whole page including the banner, related links, and other unnecessary things?Display Name– Display Name12/23/2010 22:43:47Commented Dec 23, 2010 at 22:43
-
2@xport: the point of the edit step is to allow you to select all within the textbox - that is, just the text of the post itself, not the page chrome. And again, if someone's posting 1K LoC, there is no "easy" solution - that's quite a few pages of code, far too much to even comprehend without at least a bit of time invested. Worrying about a few extra clicks to get it into your clipboard seems a bit like complaining that you have to walk all the way to the end of the pier before swimming across the Atlantic...12/23/2010 23:52:13Commented Dec 23, 2010 at 23:52
-
How to
SELECT ALL
a single code snippet region (or textbox in your terminology) that a person submit in his/her answer?Display Name– Display Name12/24/2010 00:42:54Commented Dec 24, 2010 at 0:42 -
Double the killer delete select allbobobobo– bobobobo08/19/2012 13:52:46Commented Aug 19, 2012 at 13:52
-
Maybe time to reject this poor feature request then and bring it to eternal rest? :)user152859– user15285911/19/2013 07:54:54Commented Nov 19, 2013 at 7:54
This is a terrible idea
If you're answering a question
Have higher standards. The question should basically never have that much code in it in the first place. Learn to demand a proper minimal reproducible example and keep in mind that questions are about the problem, not the original code in which it was encountered.
OP is not supposed to just ask "about" the original code, but to ask a question motivated by a problem in that code. OP is also supposed to separate the original context from the question as much as makes sense, because questions are not about the people who ask nor those who answer. They're about building a reference, so that everyone can learn answers to questions by searching the site.
Code in your answer should be similarly short. Not only are you not getting paid to write it, you aren't even specifically volunteering to write it. You're volunteering to answer a question.
If you're "researching"
If your copy-paste of code into your own code base is mindless, then you are failing your duty of care as a programmer. A code snippet posted to answer someone else's question will hardly ever work in a vacuum without adaptation to its surroundings - and if it does, it should have been packaged up in a library instead.
A code snippet posted to answer your question is still one where you are responsible for understanding the code and the explanation given by the person who posted it. Stack Overflow is not a place for people to post code to fix and other people to fix it for the OP. That is completely counter to the spirit of the site and actively degrades its usefulness for everyone else. Please see the SO tour as well as Why should I help close "bad" questions that I think are valid, instead of helping the OP with an answer? and What is the point of closing questions for details and clarity, debugging details, needs more focus, or very low quality? for details.
If you're paying attention to the code and will put in the time to review it, then you should have plenty of time to copy and paste it manually. Or even to type it in manually.
If you're a beginner, manually typing in someone else's code - carefully, making sure you have it exact - is a useful exercise. You get to understand the structure of the code and develop the discipline to make all the brackets match up, etc. that a programming language demands.
-
I genuinely don't understand why so many people are resistant to this.Karl Knechtel– Karl Knechtel11/08/2024 06:59:08Commented Nov 8, 2024 at 6:59