3

I added a comment to this question: Overloaded function template disambiguation with `std::enable_if` and non-deduced context - where a user wrote a question and provided example code that illustrated his problem. The code was spread across the question, with descriptive text in between.

To allow users to test the code, he provided a "See Wandbox example", which linked to a online C++ compiler page with his example loaded.

I would have liked it more if Stackoverflow provided a "Copy-paste" feature, which would copy an invisible code-section into clipboard. Then, askers do not need to rely on external sites to provide people with their code anymore, nor do they have to layout their example snippets as a complete working program (which adds noise - for example scope name qualifications on names, or #include / import / using lines...).

1
  • Just to let you know there is this user script that allows you to double click a code block to select the whole thing. makes copying a couple seperate blocks pretty easy. You also get code formatting extras. Mar 16, 2017 at 20:18

1 Answer 1

1

I'm conflicted about this.

On the one hand, I don't like the off-site links any more than you do, believe strongly that all code should be in the question itself, and don't much care for the clutter of useless #includes, etc. in the name of building up an MCVE (over-emphasis on complete).

But on the other hand, I'm not convinced that your proposal is really useful enough to justify developer time to build. Is it really that hard to just copy and paste a few different blocks into a text editor? I can do it in mere seconds. Besides the development time, each time a person composes a code-based question, they would have to prepare this "invisible" code snippet and ensure that it gets formatted correctly. Perhaps I'm more cynical than you, but people have a hard enough time getting code that they can see in the question itself formatted correctly; what are the odds that they'll get the formatting correct for invisible code that manifests only when copied and pasted?

I've never had an issue copying and pasting code out of posts directly from the rendered view, but even if something goes wrong there, the "edit" link can always be used as an escape hatch to get the raw, unformatted, plain-text view, and then work from there.

If something like this does get implemented, it would probably make more sense to do it by expanding the "Stack Snippets" feature. You may never have heard of this, given your C++ focus, but it's something they introduced a couple years ago that allows embedding and running code for "webby" languages (HTML, CSS, and JavaScript) directly in a post. It could theoretically be expanded to display, compile, and run code for C and C++, which might solve some of the problems you describe. Of course, this wouldn't be a trivial undertaking, because unlike JavaScript, C++ can't be compiled directly in the browser, so they would need a server to run a compiler. It's obviously doable, since there are so many other services that do it, but again, I'm not sure it's worth the development effort. I personally wasn't even sold on the benefits of Stack Snippets for JS/HTML/CSS, and although I don't spend much time asking or answering such questions, I have read a fair number of them as aids to my own feeble pursuits, and I haven't found this feature to be especially useful. It mostly just takes up valuable screen real-estate, obscuring the code I want to see. I inevitably copy and paste the relevant code into my own demo harness anyway, where I have complete control. I'd say the same would probably be true, if not even more so, for a compiled language, where I'd want to have precise control over the compiler/optimizer/linker options.

2
  • If they have that "Copy" functionality once, they can not only provide a "copy to clipboard", but also a maintained "copy to wandbox" / "copy to coliru" / ... and all the other online compilers. So, IMO it's not only about easing copy-paste into an editor. Users can instantly start to experiment with the code. Jan 15, 2017 at 16:52
  • I think that in those cases where people don't get code right that they even see in the preview, they won't even bother with providing a self-contained code block. So because there is none, they would not need to ensure that it's correctly formatted. Jan 15, 2017 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .