44

I have mostly seen that users use the JavaScript snippet option with other languages like Python, C++, and C. How can we do our best to help them understand this option?

Here is a post in which a user used that option with Python: https://stackoverflow.com/posts/52675797/revisions

Here are my suggestions:

Check the tags and look for , , etc. in posts. If not available, but a JavaScript snippet is used then raise an error.

The code formatting button doesn't look like a code button as compared to the JavaScript snippet button, because the basic icon of code is </>. {} is not too popular.

12
  • 5
    Personally I find it weird because the runnable snippet icon uses the distinctive HTML/XML <> notation (not counting the <> operator in some languages) while the regular code block icon uses the {} notation found in dozens of languages. You'd think {} would be more recognizable to a lot more people.
    – BoltClock
    Oct 7, 2018 at 4:08
  • 19
    Sometimes I think that StackSnippets should get pre-ran at posting, and that a big warning "Your Snippet doesn't compile!" should be shown when Syntax Error are thrown. Could be useful both in these cases, and in many typo we get on [javascript].
    – Kaiido
    Oct 7, 2018 at 5:31
  • @Kaiido That is a good idea.
    – Nouman
    Oct 7, 2018 at 7:19
  • 1
    It's bad enough when the OP does it, but what's even more annoying is when someone else formats the OP's code into a snippet. If such an edit has been accepted, you can @ping the editor with a brief comment explaining why they shouldn't do that. The ping won't auto-complete, but it still works.
    – PM 2Ring
    Oct 7, 2018 at 13:56
  • 1
    And @ ping the approvers.
    – philipxy
    Oct 8, 2018 at 2:23
  • 1
    @Kaiido That could be a little problematic if the question is asking "Why does this script never terminate?"
    – Mark Amery
    Oct 8, 2018 at 13:13
  • 1
    @MarkAmery I am not sure if you meant this with <sarcasm> or not, but yes, it could maybe avoid some dangerous codes as runnable snippets open to everyone. No the real case I could see is when it asks about that exact Syntax Error, but then a lookup in the body might help, or we could add a small "I know..." button.
    – Kaiido
    Oct 8, 2018 at 14:26
  • @Kaiido I agree.
    – Nouman
    Oct 8, 2018 at 14:27
  • @Kaiido That would not be a particularly useful warning to present to users since HTML, CSS, and JavaScript are compiled languages, and Stack Snippets are only for HTML, CSS, and JavaScript.
    – TylerH
    Nov 2, 2021 at 14:05
  • @TylerH sorry I don't understand your comment. Could you rephrase it please?
    – Kaiido
    Nov 2, 2021 at 14:11
  • @Kaiido Your comment suggests providing a warning about code not compiling in the Stack Snippet editor, but the Stack Snippet editor only supports languages that don't compile, by design. So all code ever entered would throw that warning, and it wouldn't be an actual problem, thus such a warning is not useful.
    – TylerH
    Nov 2, 2021 at 14:18
  • @TylerH Ok thanks for rephrasing without the weird compile/don't compile typo. So, what I said back then was to provide that warning for "Syntax Errors", a.k.a "the dev typed something stupid here", a.k.a a problem between the chair and the keyboard, which would definitely be useful for a lot of [javascript] typo questions (glad to find out I still agree with my past self ;-P)
    – Kaiido
    Nov 2, 2021 at 14:21

2 Answers 2

12

My suggestion:

Add a prominent "I just want to insert a regular code sample" button to that popup (perhaps in the form of a tabbed interface).

The reason being that once you open that popup, it very well may seem like it's the only place you can insert code from.

Should we actually make inserting regular code part of that UI (as in you paste the code there)? Sure, why not.

What if we make the button itself more general and, when you press the button, you're first presented with two buttons - one for regular code and one for JS/HTML/CSS? [I'm assuming experienced users won't like this, but I'm not sure what a good alternative is - adding another button to the editing interface, which opens the popup in the regular code tab?]

While we're at it, we can probably add some MCVE tips to the UI and even remove excessive indents when posting.

What about the current way to insert code? What if we replace that with an "indent" button, which does exactly what it does now. Would this confuse people? Probably, but that's probably more a markdown understanding issue, which presumably already happens.

3
  • 1
    Yeah. That will confuse people.
    – Nouman
    Oct 6, 2018 at 6:59
  • 3
    +1, I think you've got the kernel of a good idea here, even if the details might need fine-tuning. We should have an "insert code" pop-up of some kind, because Markdown code formatting is not trivial for newbies. And it should have a language selector, so that it can automatically generate the right syntax highlight comment, because that's not trivial either. At that point, why not make "JS / CSS / HTML snippet" the first option in that selector (after "Unknown" or whatever the default should be) and make selecting it split the edit pane and enable the rest of the Stack Snippet editor UI? Oct 8, 2018 at 1:19
  • 3
    ... Of course, ideally SE would integrate something like TIO (hey, it's open source and written by a codegolf.SE mod) so that we could have Stack Snippet -like functionality for all languages. Or at least most of the common ones. Oct 8, 2018 at 1:27
-1

I think it's likely because the button is on the end and has a filled background, so it looks more prominent than the Code Sample button. And I agree it looks more inserted-code-like because of the image of a page around it. A brand new programmer is not going to immediately pick up on the difference in significance of {} vs <>, but since they aren't even next to each other, the hollow {} button in the middle might not even be noticed.

Suggestion: Change the JavaScript snippet button to have "JS" on the icon instead of "<>". And possibly move it to the left of the Insert Image button. Change the Code Sample button to also have a page background.

1
  • 1
    Stack Snippets are also for HTML and for CSS, not just JavaScript. They're often used for CSS issues. Nov 2, 2021 at 13:57

You must log in to answer this question.

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