2

I recently posted a question which contained a reference from code posted on another site. In order to not use only link from the other side, I put a code snippet aside the link (this way, in case the link ever gets broken, the code will be still available in the question).

I had a problem with a very minor change in the code which I explained exactly where and also added a code-block describing the specific change. But, the snippet itself was very large and made the question appear very long. I could cut off some of the code but I think I would much prefer it if I could just put the snippet without all the code copied to the question and only visible for view/edit for those who really want to answer. This way the reference to the external link would remain much more "whole" but still allowing to focus on what's important in the question.

1

1 Answer 1

4

Questions should first and foremost contain relevant code in the question itself.
Links to external sites are nice, but lose value as soon as the problem is solved.

Your priority should be in writing an Minimal, Complete, and Verifiable example.
Often enough, those examples can be small enough that you don't even need to hide the code.

If the code's still quite long, you could use stack snippets, and "Hide" the code be default:

enter image description here

This will result in something like this:

(function someFunction(){
    alert('Hidden!');
})()
<div>
  FooBar
  This is one loo
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  ong snippet.
</div>

Or just let the scrollbar show:

<div>
  FooBar
  This is one loo
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  o
  ong code block.
</div>
2
  • I was just putting something like this together. +1. I think the js hide: true part of the leading HTML comment is responsible for that collapsing behavior.
    – ryanyuyu
    Oct 13, 2015 at 13:17
  • 1
    @ryanyuyu: That is correct. (The js is to identify the section, hide: true hides the snippet by default)
    – Cerbrus
    Oct 13, 2015 at 13:18

You must log in to answer this question.

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