Quantcast
Channel: Active questions tagged code-formatting - Meta Stack Overflow
Viewing all articles
Browse latest Browse all 180

What is the preferred method for formatting code?

$
0
0

My primary question is

What is the preferred method for formatting code?

followed by

Is the formatting help at odds with the preferred formatting method?

The sidebar for the "Ask a question" interface currently looks like this:

The first two bullets describe how to format code with fences. The sixth describes how to do it with spaces.

Notice that "indent code by 4 spaces" is still there. However, you could be forgiven for not noticing it.


Historical Context

When I first started asking questions on Stack Overflow, I believe the sidebar recommended something else for formatting code. My best guess is that it recommended something like <pre> tags:

You can still format code using tags that can't be used in the code itself!Who knew?

So I actually don't remember exactly what was the method highlighted in the sidebar at the time. I just remember that the very first thing that happened after I made my first post was that someone edited the post to remove the recommended formatting method and indent the code four spaces. At the time, I was startled, to say the least. However, I got the hint and ever afterward used four spaces to indicate code.

I was startled because the community's preferred method of formatting code contradicted the formatting help. A problem that still seems to be happening today.

Today, I was curious about the new "Ask a question" interface, so I decided to have a look at it. I was startled to see this:

First bullet says to format code with fences. There is no mention of using spaces.

Why is the official Stack Overflow code formatting help at odds with the accepted conventions?

I am not requesting that backticks be supported. I am asking

  • Which code formatting convention is preferred?
  • If four spaces is preferred, why doesn't the documentation reflect this?
  • If neither format is preferred, why are backticks more heavily emphasized in the help shown to new users and question askers?

I am not asking about inline backticks. I am asking about

```backticks used to format code```

versus

    spaces used to format code

Viewing all articles
Browse latest Browse all 180

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>