28

We've all seen new questions with code that looks something like this:

func someFunction() {
// code here
more here
etc.

}


Obviously they posted:

func someFunction() { // code here more here etc. }

and saw what a mess it is. Then they simply indented the first line and said "good enough".

We are lucky to at least get code formatted that well but it would be great to get it done correctly the rest of the way:

func someFunction() {
    // code here
    more here
    etc.
}

Can the "Ask Question" screen somehow teach the user to select all of the code they pasted and then press Ctrl-k to indent it all?

I don't think enough people know about Ctrl-k or even that code should be indented 4 spaces to be formatted as code.

Maybe a reminder can be shown if certain strings are found at the start of a line such as }.

I guess this is partially an enhancement request and partially a discussion on good ways to help teach new(er) users how to format their code properly. I spend way too much time cleaning up users' posts.

11
  • 5
    Another thing that gets me every time is that I forget the when within an indented block hitting enter doesn't keep the indent level therefore you have to mash space bar again to get to the right point.
    – Script47
    Commented Oct 25, 2018 at 16:35
  • 14
    It isn't always obvious to me how much of my free time I should invest to solve a problem or fix a question. The threshold for asking for help is very low at SO. When I see a post like that then I know. It better be an interesting problem, turd polishing doesn't help anybody. Commented Oct 25, 2018 at 16:42
  • 1
    @HansPassant Sometimes when the code is formatted very poorly I copy and paste into my IDE and let it format it correctly. I'll then remove excessive blank lines and update the post with the reformatted code. It makes it much easier on everyone else that attempts to read the question and hopefully it teaches the OP that there is a proper way to format their own code.
    – rmaddy
    Commented Oct 25, 2018 at 16:56
  • 5
    I'll try this another way, beware that you are removing very important information from the question. This is bogus code that the OP did not actually try himself. Only do this after the question is satisfactorily answered. You'll inevitably find yourself having to make a lot less edits. Commented Oct 25, 2018 at 17:04
  • 5
    @HansPassant No, I'm only fixing formatting where formatting is irrelevant to the question being asked. I'm simply making it readable for everyone else. But none of this has anything to do with the question I've posted here so let's get back to that, thanks.
    – rmaddy
    Commented Oct 25, 2018 at 17:07
  • 1
    Info: It's already clearly mentioned in the "formatting help »" link.
    – user202729
    Commented Oct 27, 2018 at 9:52
  • @user202729 Considering how few people know about it and how few new users properly format code in the questions, clearly no one is clicking on the help link. That's point here. Finding a way to better help the user. And the formatting help ink is buried. You need to tap the barely visible little circled ? icon. Then click on Advanced Help. No one does that.
    – rmaddy
    Commented Oct 27, 2018 at 14:56
  • 1
    @rmaddy "Barely visible little circled ? icon"? Not necessary.
    – user202729
    Commented Oct 27, 2018 at 16:39
  • 3
    It would also help to emphasize that they can (should, must) check the preview in the browser before submitting their question/edit. 5 broken iterations of the same question in 3 minutes can be nerve-wrecking to watch. Commented Oct 27, 2018 at 20:50
  • 1
    Related: support triple-backtick code blocks
    – pkamb
    Commented Oct 28, 2018 at 8:08
  • @AndrasDeak At least checking the preview doesn't require clicking any link (it can't be more obvious...)
    – user202729
    Commented Oct 28, 2018 at 14:40

0

You must log in to answer this question.

Browse other questions tagged .