2

This post is related to two older posts. One is an old feature request, Promote Stack Overflow HTML, JS, CSS Stack Snippets, which did not receive much attention but I think is good. The second is a nice post discussing bad snippet usage - Should it be more obvious that stack snippets are only meant for HTML/CSS/JS?.

According to the second post, there may be around 30% questions (only, no answers) using snippets with wrong tags (no CSS/HTML/JS). While this is bad usage, it is rather easy to fix on edit.

The other problem - H/J/C questions not using the snippet (specifically where the code is in the question, not a jsfiddle link which is worse in my opinion) is more annoying. It seems like it happens often, with new users at least (Is there a percent somewhere we can see, like that second post? Might be useful to see if this is actually widespread). For me at least fixing these is a bit tedious.

So I was wondering, is there any way to mark some text, ctrl-something to get it surrounded with the appropriate snippet comment line, and similarly for H/J/C?

I would like to stress - I am not requesting any language detection here. It's up to an editor to mark the text they want to enclose in the tags. That means for usage of JS, HTML, and CSS, you would have to mark the text 4 times (once for each language, and one each to enclose everything in the snippet. Also, I'm just asking if there is some way to get this done currently; so it's not really a feature request.

Also, is it easy to detect a snippet in the question (answer)? If so, might be worth turning this into a feature request to address both of the above - on pressing "post", an appropriate warning such as

You have tagged javascript but you are not using the snippet tool

with an appropriate image, and vice-versa can pop up to enlighten the user. This is short enough and I'm guessing most new users just make an honest mistake/miss the snippet so it might actually help.

Discussion of the feature part of the question

@Oleg noted this warning could become annoying for one line code pieces and the such, and I agree. The only workaround I can think of is a rep barrier where no warnings show (a small one, ~10-20).

As @Boltclock stresses, this should be a mere soft improvement suggestion, not a warning, and have no repercussions. New users pasting code dumps should just be notified of this.

Feature basics (updating with discussion):

  1. No language detection should be implemented. This is a tag (and snippet) detection suggestion.
  2. Should have a very low rep barrier, just so new users get acquainted. After 10-20 rep, no warning should appear.
  3. Should pop up once per question as a suggestion only, perhaps with a link to snippet usage FAQ. This should not be a warning.
  4. This won't fix the question for the user, just point them in the right direction of what to do; since there is no code detection, it would be impossible.
5
  • Upvoted but I disagree with showing a warning "You have tagged javascript but you are not using the snippet tool" there are plenty of javascript questions that don't need a snippet and this can be rather annoying.
    – Oleg
    Apr 1, 2018 at 21:39
  • @Oleg Questions with no code at all? In that case regular code detection? Or are you referring to short one line pieces of code? If that's the case I'm guessing that would be hard to implement. I'll add your caveat to the question.
    – kabanus
    Apr 1, 2018 at 21:41
  • So I was wondering, is there anyway to mark some text, ctrl-something to get it surrounded with the appropriate snippet comment line, and similarly for H/J/C? You mean copy/pasting the snippet tags? <!-- begin snippet: js hide: false console: true babel: false --> <!-- end snippet -->
    – BSMP
    Apr 2, 2018 at 19:03
  • @BSMP Yes, except I'm not going to try and memorize that or keep it in some file and copy paste it on demand. This is to encourage editors to improve questions in a way they might otherwise not, I don't think copy-pasting is a good solution, as it doesn't really save work.
    – kabanus
    Apr 2, 2018 at 19:54
  • Think pasting code, marking, and Ctrl-K. That behavior.
    – kabanus
    Apr 2, 2018 at 20:02

1 Answer 1

5

Keep in mind:

  • Such a feature would need to be able to identify and distinguish all three languages correctly and reliably. Not all questions contain all three languages.

  • If only one language is featured, and it is not JavaScript, it will almost certainly not benefit from a Stack Snippet and there is no reason to make it one:

    • An HTML fragment by itself does not demonstrate anything when run, unless it's a form or some other interactive module.
    • A CSS snippet by itself literally does nothing when run, unless it's applying styles to html, body, or any other pre-existing elements in the Stack Snippet boilerplate.
    • A JavaScript snippet that relies on DOM manipulations but doesn't come with the requisite markup will do nothing because there's nothing to manipulate.
  • While code that is suited to Stack Snippets will often greatly benefit from the feature, reviewers and answerers should not grow too dependent on them to evaluate and answer questions. They are intended as a value-add, not a handholding tool or a requirement for good, on-topic questions. Such a feature should be designed to promote Stack Snippets without suggesting that the asker will get into trouble for choosing not to use them, especially when their use case simply isn't amenable to Stack Snippets.

4
  • Thanks for the detailed response. I disagree on some counts : 1. No language detection, only tag detection and snippet detection is usually enough (and reduce complexity of this as a feature immensely). 2. Actually, HTML by itself can be a layout question so it may indeed benefit. Even if it requires CSS additions, at least an answerer will have the template ready. **I absolutely agree this should be a mere succession to the user, with no repercussions whatsoever ** I'm adding these clarifications, thanks.
    – kabanus
    Apr 2, 2018 at 8:23
  • I missed an important aspect of your point - the feature won't autocorrect, just point to the snippet button. Added that as well. That's better IMO from teaching the user anyway.
    – kabanus
    Apr 2, 2018 at 8:36
  • @kabanus: Language detection is so that the feature can convert code blocks that aren't already delimited with <!-- language: lang-html/css/js --> language hints to Stack Snippets with the appropriate hints.
    – BoltClock
    Apr 2, 2018 at 10:59
  • ahh you missed a part of what I said. It would be up to the editor to mark the piece of text they want to delimit. Absolutely 0 "smart" behavior, just a keyboard shortcut/button to make things easier for editors. I edited the question to reflect this - worst case, you have to mark text 4 times. Still would be easier than manual copy to the snippet tool.
    – kabanus
    Apr 2, 2018 at 11:59

You must log in to answer this question.

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