35

I've seen many questions where Java, SQL, etc. code was marked up using a snippet tool. In such cases we are presented with a more cluttered screen for no benefit at all.

Since currently only HTML/CSS and JavaScript code is supported, why not produce a warning when saving the question if it does not have any of these tags? When (and if) additional snippet functionality is developed, we will just need to expand the tag list.

My suggestion is somewhat in the middle between "do nothing now" and "remove automatically".

I believe that a warning is a gentle enough measure to get some additional clarity.

8
  • 10
    Snippets get misused even when it's an HTML/JS question, often having code that does not work in itself. People just see the "insert code snippet" button and use it over the regular code block button. Likely because the snippet editor has a more pleasing edit UI, or its name was misunderstood. It really should be renamed to Insert Self-Contained Working Code
    – SeinopSys
    May 31, 2015 at 8:59
  • @DJDavid98 - Very good point.
    – PM 77-1
    May 31, 2015 at 22:47
  • 1
    actually how about a button that properly adds four spaces to the beginning of each line within the selection
    – user4639281
    Jun 1, 2015 at 6:48
  • 3
    @humble.rumble Is the {} button not proper enough for you?
    – Siguza
    Jun 1, 2015 at 6:50
  • How about changing the tool tip from "Code snippet Ctrl-M" to "HTML/Javascript Code snippet Ctrl-M"
    – samgak
    Jun 1, 2015 at 6:54
  • @Siguza it only indents the first line, leaving the closing brace out of the code block, and poor indentation. I see it all the time.
    – user4639281
    Jun 1, 2015 at 7:00
  • 1
    @humble.rumble If you paste your code first, select it and then use the {} button, every line is indented. But I agree that this is an issue.
    – Siguza
    Jun 1, 2015 at 7:02
  • I've just updated the figures in the query I wrote in my answer on the linked post: meta.stackoverflow.com/a/277747/57475, it still shows that 30% of questions aren't using the correct tags when adding snippets.
    – Tanner
    Jun 1, 2015 at 8:42

1 Answer 1

16

If a user right-out ignores the "HTML", "CSS" and "JavaScript" labels on the snippet UI, I think they are rather likely to ignore tooltips and popup warnings just as well.
As stated in the first meta post you linked to:

The users [...] seem to be brute-forcing their way by pasting their code dump into the first box they see.

Another problem is that even if the snippet contains HTML/CSS/JS code, the vast majority of snippets are still not actually runnable.


Edit:

In my original answer I suggested a privilege, but I feel like I need to say more to that.

In light of that, I suggest making access to the snippet button a privilege, awarded somewhere between 25 and 100 reputation.

This will certainly not prevent all misuse, but most, I think.
Manually adding the required HTML comments should still be possible though, because if a user knows how to do that and is willing to go through the effort, they can be assumed to have a very good reason to do so.

Now the problem with that is of course, as AJPerez stated in the comments below:

If a post could actually benefit from a runnable snippet, let the user add it.

I very much share that opinion, but if it stands "prevent 50% snippet misuse" versus "prevent 90% snippet misuse and block rep<25 users from accessing it", I'm afraid I'm going with the second option.
That numbers are just speculation of course, but I've searched for an hour and a half, and out of all misused-snippet posts I found, the OP with the highest reputation had 26.

Also, Tanner suggested "better guidance" in the comments.
If there is at all a canonically correct approach to address any misuse, then it is exactly that: better guidance.
The problem with this, however is: How do you make the users listen (or read)?
Because show me a user who ignores the "HTML"/"CSS"/"JS" labels, but listens to a warning popup, especially after having their code already pasted.

However, I think by slightly modifying the "warning idea", you could actually get the user's attention.
Because currently it goes like this:
The user is looking for somewhere to paste their code. As soon as they find it, it's game over, their only goal now is to reach the post button. (I'm sure there are less aggressive users as well, but to me it actually feels like 90% of low-rep users are like this.)
So instead of showing a warning after the user had the chance to paste their code, it should be shown before.

For example, when opening the snippet UI for the very first time, instead of the editing panel popping up, why not make something like:

Snippet warning

(I think the most important thing about it would actually be the WARNING at the top, to get the user's attention.)
That might still not catch all evildoers, but I imagine it having a bigger chance of doing so that a warning after all the pasting and editing.

So, my new suggestion is to implement a scary-looking first-time warning like the one above, and if still too many low-rep'ies just brute-force their code into the snippet editor, just cut the crap and make snippet editor access a privilege as suggested in my original answer.


Now in addition to that, I suggest a couple of relatively small, but in my opinion still important changes:

  • Rename the "Code snippet" button.
    While the name "code snippet" is certainly not wrong, I see it as misleading, because it is only for HTML/CSS/JS, and only if the code is actually a runnable example.
    I suggest renaming it to "Browser-runnable code".
  • Add an UI to the "Code Sample" button.

    1. Clicking the {} button without having any text selected adds the following to your text box:

          enter code here
      

      But this only works for a single line of code, because as soon as you hit Return or paste some code with line breaks, only the first line will be indented.

    2. Clicking the {} button while having text selected will add/remove an indentation by 4 spaces, but according to user humble.rumble, this won't always work (see comments on the question).
    3. A UI is just more appealing, especially to new users.
  • Rearrange the buttons.
    Currently there's the image button between {} and <>, which is, in my opinion, a bit confusing since I'd expect buttons with similar or related functionality to be next to each other. Finding a completely unrelated button between them makes me feel like it was intentionally placed there to separate the other buttons for a reason I can't seem to understand.
  • Change the images.
    Until an hour ago, I didn't even know what the {} button really is, because I never even bothered to look at it.
    The button I did know about though, is <>, simply because it looks more like "insert code" than {} does, so a few months ago when I was new to the site and went to find out where the "Run Snippet" thingies were coming from, that's the button I found first.
    I imagine the same thing happening with a new user: Out of {} and <>, they try <> first, and - "Oooh, what have we here? Is that a nice UI to paste any code I want? Awesome!"
    After all, I think the first impression a user gets is very important.
7
  • 2
    i don't think making it a privilege is the right approach.
    – Tanner
    Jun 1, 2015 at 8:44
  • 1
    @Tanner Why not? Privileges are directly bound to reputation, and (quote from the help center): "Reputation is a rough measurement of how much the community trusts you". The vast misuse of snippets proves that most new users cannot be trusted to use that feature right away, so what better approach is there than to make it a privilege?
    – Siguza
    Jun 1, 2015 at 8:58
  • a warning based on tags used or better guidance would be more useful. restricting the editing facilities on posting isn't done anywhere from what i know, so don't I don't think they would add it just for this.
    – Tanner
    Jun 1, 2015 at 9:44
  • @Tanner I certainly agree on better guidance, but how can you ensure that it actually reaches the users? Because those who read through the help center are most likely not the ones misusing snippets. Also, tag filtering will certainly rule out some misuse, but there's still a lot of HTML, CSS and especially JS "snippets" that are just not runnable. And as already stated, I believe that users who ignore box labels will ignore warnings too. A tag-based warning (or a warning at all) certainly won't do any harm, but I doubt it will catch enough cases (>=75%) to really address the issue.
    – Siguza
    Jun 1, 2015 at 10:22
  • 4
    +1 for the last bullet point. "{}" as button icon is bad UX.
    – user11153
    Jun 1, 2015 at 11:38
  • 1
    I agree with everything you proposed, except with the "make it a privilege" part. I've seen too many "I don't have enough reputation to add images so I leave the link instead". If a post could actually benefit from a runnable snippet, let the user add it. We just have to make both code buttons more clear... for everybody, not only 1 rep users.
    – AJPerez
    Jun 1, 2015 at 12:16
  • 1
    @AJPerez The same could be said about the commenting privilege: "If a post could actually benefit from a comment, let the user add it", but users with a reputation < 50 can't do this. And even though this results in quite a number of answers that should be comments every single day, it is still around. Hiding a UI element would do much less harm than that. Also, the amount of low-rep users who know how to use this feature and have code that fits it is most likely <1%. If there's an option that better tells people capable of using the feature apart from those that aren't, I'll gladly take it.
    – Siguza
    Jun 1, 2015 at 12:44

You must log in to answer this question.

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