30

I very often see new contributors asking questions like this:

function foo(){
  return "bar";

}

enter image description here

I personally don't know how they get there, especially for the image one. But since this happens very consistently, is there possibly a design flaw in the SO post editor UI leading new users to create such posts?

30
  • 20
    I find it more often they'd miss out the first line. Most likely because they copy/paste from a file where everything is already indented but don't copy the leading whitespace from the first line of code.
    – VLAZ
    Commented Jan 27, 2022 at 8:34
  • 1
    @VLAZ but the editor automatically embed the image when I click "Add Picture". I have to manually delete the leading [! and trailing ][1] around it to make it display like this. How come new users all do this so consistently.
    – Ricky Mo
    Commented Jan 27, 2022 at 8:37
  • 40
    The embedding is not enabled for new accounts to mitigate possible spam and abuse.
    – VLAZ
    Commented Jan 27, 2022 at 8:40
  • 3
    FWIW, even though most of these can be explained easily, that doesn't mean there isn't a design flaw that can – perhaps – be fixed. Commented Jan 27, 2022 at 8:53
  • 10
    I think the code appearance issue comes from them copying some code that isn't indented enough, pasting, submitting, seeing that the first line is non-monospace because it isn't indented enough (but all other lines except the last are) and editing to make the first line appear correct but forgetting the last line. To truly know though, why not ask the next person you see doing it?
    – Caius Jard
    Commented Jan 27, 2022 at 9:14
  • 2
    @VLAZ I don't have a solution either, and I totally agree that ultimately the issue is that people just don't care. I'm just hoping that someone who is in a less grumpy mood than me isn't put off from answering because there's an impression that "it's obvious and won't matter" or such. Commented Jan 27, 2022 at 9:23
  • 2
    I think more of the help given for code formatting should be changed to instruct users to use the triple backtick. That would be harder to mess up than the indent.
    – BSMP
    Commented Jan 27, 2022 at 9:24
  • 6
    @BSMP Good point. Why don't Ctrl+K add triple backticks instead of indent? I remember when I wrote my first post, I found Ctrl+K quite confusing to use and I didn't know triple backticks was a thing because Ctrl+K (and also pressing the {} button) leaded me straight to indentation.
    – Ricky Mo
    Commented Jan 27, 2022 at 9:32
  • 3
    @RickyMo I think it does the indentation because....it was never changed. The triple backtick is a more recent addition, indentation for code was in place since much longer.
    – VLAZ
    Commented Jan 27, 2022 at 9:39
  • 5
    There is a FR to change the default: Change the code block button from inserting indentation to triple-backticks. No response to that but there is a link to here where it says they won't change it basically because they are working on a new editor.
    – VLAZ
    Commented Jan 27, 2022 at 9:42
  • 1
    @BSMP FWIW, the blockquote button doesn't work with code fences, which is to say, they're not perfect.
    – wjandrea
    Commented Jan 27, 2022 at 21:18
  • 3
    Mistakes with markup can happen, BUT... isn't there a live preview right below the edit box, allowing the user to proof-read their post as many times as necessary? Isn't there the feature to edit the question even after it was posted (allowing for further proof-reading and potential corrections? (I've never asked a question, but when I tried it now, the button seemed to say "Review your question", so I presume there's yet another stage allowing for corrections in the process). With all that, why do we still end up with so many malformed questions? Is that really a design issue or does PEBKAC?
    – Dan Mašek
    Commented Jan 28, 2022 at 0:22
  • 2
    If you click the code sample button, then paste your code, only the first line will have the code formatting indent. Since most often the code is a function/method, its body is already indented, so as the result it will be formatted as code, although at the same level as the first line. The closing brace has no indent, so it does not get formatted like that.
    – Didier L
    Commented Jan 28, 2022 at 11:25
  • 3
    @wizzwizz4: You don't have to know markdown syntax; there's a {} code formatting button that works similar to a WYSIWYG word processor. You just have to care enough to not crap on the lawn of the people you're asking for help, i.e. review your question and maybe take a couple minutes to figure out the editor. I have near-zero sympathy for people with boring questions who have that little respect for the people who's attention they're taking. I can see not noticing a stray } after doing what you describe in your answer, but fubared ugly indenting or total lack of code format is just rude. Commented Jan 29, 2022 at 10:59
  • 2
    @wizzwizz4: Was thinking about this some more: if formatting is the only thing wrong with a question, and it's otherwise interesting, and not just another variation on a common problem, that doesn't bother me too much. But when the question is already poor, like a low-effort code dump or homework dump, that's when bad / no formatting fully solidifies my impression of a lack of respect for the people reading the question, and their time / attention. Commented Jan 29, 2022 at 22:04

2 Answers 2

22

I have done both of these. Here's why they happened to me.

Code blocks

  1. Type / paste in the code.
  2. Oh, it's not formatted.
  3. Move the cursor to the start of the first line.
  4. Hold Shift.
  5. Hold Down.
  6. Click “Code Sample <pre><code> Ctrl+K”.
  7. Post.

Clicking the “Code Sample” button will indent all lines containing selected text. If you've placed the cursor at the very beginning of the first line, you will end up not selecting any of the last line, and that last line will not be included in the four-spaces-indented block.

Image links

  1. Upload image.
  2. Post.

New users don't have the privileges to post an image, so it gets automatically converted into a hyperlink by the Stack Exchange software. (And if SmokeDetector is anything to go by, you should be thankful that the system behaves this way!)

Related phenomena and speculations

Consider a fictional question:

Hello, I have a problem with this code :

#include "stdout.h"

int main () {

printf("Hello world");

}

It works but there is a warning that I dont understand: helloWorld.c:3: warning: implicit declaration of function 'printf'

Inline code paragraphs

This can be explained by a user doing the following:

  • Type / paste in the first line of code.
  • Oh, it's not formatted.
  • Select the first line, and click on the formatting button at the top.
  • Deduce how the formatting works, adding backticks and paragraph breaks as appropriate.

or:

  • Type the start of the question.
  • Click on the code icon, to change it to a code font, without first pressing Enter.
  • See `enter code here`.
  • Paste in the code, breaking the formatting.
  • Deduce how the formatting works, adding backticks and paragraph breaks as appropriate to fix it.

Unformatted error message

The error message is not in a code block. This is because it is not code; it is an error message. (The asker hasn't noticed that error messages often contain ASCII art, and hasn't realised that errors should always be posted in monospace.)

9
  • 1
    But why did (past) you not also select the last line before pressing Ctrl+K? You just had to press Down Arrow one more time. I didn't understand why you say the last line isn't selected because you made sure the beginning of the first line is selected.
    – mkrieger1
    Commented Jan 27, 2022 at 23:24
  • 3
    @mkrieger1 Pressing down arrow one more time doesn't work if the code is at the end of the answer, with no new line afterwards. My habit, when I was a frequent Stack Overflow answerer, was to select the code, go down to the last line, and then press End to select to the end of that line. (I say because, because the “select all the lines” procedure that I find intuitive does work if I'm less neat about it.)
    – wizzwizz4
    Commented Jan 27, 2022 at 23:57
  • 3
    Okay, being the last line of the text box, it makes sense.
    – mkrieger1
    Commented Jan 27, 2022 at 23:58
  • 3
    Is that an operating specific thing? I just tried it on Mac and it does indeed select the last line as well even if there is no trailing line break.
    – Clashsoft
    Commented Jan 28, 2022 at 21:45
  • @Clashsoft It's probably OS-specific, yeah. (That would explain why I have muscle-memory for doing it wrong.)
    – wizzwizz4
    Commented Jan 28, 2022 at 22:08
  • And then there is the annoying bug with doing a numeration or bullet point style list with a code block following where the code block is not picked up correctly. Commented Jan 29, 2022 at 10:06
  • 2
    @Clashsoft: Or perhaps a browser thing? Chromium on GNU/Linux does allow you to shift+down_arrow on the last line to select it; tested just now. Of course if I actually wanted to select from a certain point to the end of the textbox, I'd ctrl+shift+end, which also works, and I assume works portably even in cases where shift+down wouldn't select the contents of the last line. Commented Jan 29, 2022 at 10:48
  • Re "...Down": Do you mean the down arrow key? Commented Jan 29, 2022 at 16:52
  • @PeterMortensen I do.
    – wizzwizz4
    Commented Jan 29, 2022 at 19:03
7

I've seen a number of posts where the code snippet just seems to be pasted in. Most of the snippet happens to already be indented with 4 spaces, so it gets formatted. There are dangling brackets or the code isn't consistently indented, so a few hang out. My impression that new users don't plan on formatting their code to begin with, and are probably surprised/confused when part of the code does get formatted, but don't know/care to fix it the part that isn't.

With regards to images, I figured it was the same thing, but when I tried it, I discovered that pasting a picture results in this markdown:

[![enter image description here][1]][1]

I don't remember this always being the case but it's likely that it's just what wizzwizz4 said about images.

You must log in to answer this question.

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