<p>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 <a href="https://stats.stackexchange.com/a/125678/22228">the code interesting, or OP expressed an interest</a>, I'm likely to continue to do so, but for a <a href="https://stats.stackexchange.com/a/87746/22228">workaday plot</a> the temptation to "provide, but hide" is strong.</p>

<p>In the thread "<a href="https://stats.meta.stackexchange.com/questions/425/shall-i-attach-pieces-of-code-to-my-answers">Shall I attach pieces of code to my answers?</a>", the concept of a "show/hide" button for code was marked as rejected. But the reception to the later thread "<a href="https://stats.meta.stackexchange.com/questions/891/do-we-need-to-hide-some-lengthy-content-in-answers-or-questions">Do we need to hide some lengthy content in answers or questions?</a>" 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.</p>

<p>In an answer (it happens to be <a href="https://stats.stackexchange.com/a/128719/22228">this one</a>, 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 <a href="https://stats.stackexchange.com/revisions/128719/4">code-containing revision</a> 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.</p>

<p>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?</p>
