11
$\begingroup$

Sometimes code is an important part of an answer. Other times, code is interesting and potentially useful to others, e.g. how to construct a plot, but doesn't help the OP in answering their question. I try to append code for plots (partly as it frustrates me when I can't replicate or adapt for personal use the beautiful plots of others!) and if I find the code interesting, or OP expressed an interest, I'm likely to continue to do so, but for a workaday plot the temptation to "provide, but hide" is strong.

In the thread "Shall I attach pieces of code to my answers?", the concept of a "show/hide" button for code was marked as rejected. But the reception to the later thread "Do we need to hide some lengthy content in answers or questions?" seemed positive! I'm not satisfied with the suggested solution of linking to a repository elsewhere - eg potential link-rot issues - and the presence of scrollbars on long code extracts only alleviates such concerns, doesn't resolve them.

In an answer (it happens to be this one, but I think that's unimportant) I included some code for data and plotting at the bottom, then quickly (to avoid spamming the main page) re-edited it, deleting the code, but inserting a link to the code-containing revision by the graph. The result is that the code is stored on the main CV site, is accessible to interested readers, but does not clog up the answer.

In retrospect I am not sure whether this was a good idea. There was support in the "Shall I attach" thread for the inclusion of such code, even if peripheral to the main answer, and I'm basically using a bit of a hack to conceal it. It certainly wasn't a use that edit history was intended for. Moreover I don't know whether edit history links are considered stable in the very long run on Stack Exchange (I suspect so because I believe licensing here requires authorial attribution which is visible via history, but on the other hand there are occasional rumblings that old comments on SE sites will someday be purged, so just because material is hosted here doesn't necessarily mean it's here to stay). Is this a practice I should actively engage in, use sparingly, or avoid altogether?

$\endgroup$
  • 4
    $\begingroup$ Wow, this is one heck of a convoluted hack! +1 if only for coming up with it. $\endgroup$ – amoeba Dec 15 '14 at 23:54
  • 4
    $\begingroup$ The show/hide functionality would be great; it is a pity SE doesn't have it, and I don't actually understand why not, but alas. Until such functionality appears, I think separate repository is a neater solution than yours. I suppose one can be very sure that links e.g. to gist.github.com will not rot. One does not need to register there to paste some code, there is syntax highlighting, etc., so I think it's pretty convenient. $\endgroup$ – amoeba Dec 15 '14 at 23:59
  • 3
    $\begingroup$ BTW, regarding syntax highlighting: SE does have it, but it only works automatically if the question is tagged with the corresponding language tag. That's why your code e.g. here is not colored. You can manually turn it on by writing <!-- language: lang-r --> and leaving empty line (!) before the code block. If you write language-all then all subsequent blocks will also have highlighting. See here for more details. $\endgroup$ – amoeba Dec 16 '14 at 0:02
  • 1
    $\begingroup$ +1. Personally, I am fine with the code block scroll bar. It is common here in CV high quality answers providing the code (to reproduce pictures) at the answer's end. Also, I do not think you are abusing the feature. $\endgroup$ – Andre Silva Dec 16 '14 at 0:24
  • 2
    $\begingroup$ What in interesting idea. I do wish we could just hide/show code. $\endgroup$ – Glen_b Dec 16 '14 at 22:41
11
$\begingroup$

My answer is simply: Please just show the code.

To downplay the code, there are obvious possible signals, such as: The code is given at the end of the answer for those interested. Here is the code for those interested.

If the code is not interesting or useful or not in a language you use or can translate, you can ignore it in a flash. That comes really easily and you don't even have to practise.

If the code is any of those good things, excellent.

People who provide code can be assured that many appreciate your time and effort and try to reciprocate when they can.

Note that even code someone never uses can be a stimulus. Sometimes I see something done easily in some other language, and think: I should be able to do that just as easily in my favourite language. Occasionally, something is apparently harder work than in your own favourite language, and then there is an enjoyable wry smile.

$\endgroup$
4
$\begingroup$

I don't see any problem with using the revision history in this way. It seems fairly clever to me. One thing you should be aware of is that if you have too many edits (10, I think) your answer will be converted to CW automatically. However, you can flag your answer and the moderators can convert it back.

I suspect the edit revisions are at least as stable as github. Regarding the concern that old versions can be curated like comments, you should know that deleted comments still exist somewhere. For example, moderators can see them, I believe. (Users with >10k reputation can see deleted answers--and deleted questions, if you can find a link to them--but not comments.)

$\endgroup$
  • 4
    $\begingroup$ +1. If I am not mistaken the 10 edit conversion to cw feature does not exist anymore. When I have the chance I will try to look for the source of this information. $\endgroup$ – Andre Silva Dec 16 '14 at 19:34
  • $\begingroup$ Thanks for letting me know, @AndreSilva. $\endgroup$ – gung Dec 16 '14 at 19:36
  • 2
    $\begingroup$ Found it: meta.stackexchange.com/questions/227290/… $\endgroup$ – Andre Silva Dec 16 '14 at 20:00

You must log in to answer this question.

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