Personally, code fences are cleaner (less whitespace) and are parsed more quickly due to the ability to hint at the language via cpp,lang-none,js, etc.

Other than requiring indenting to use code in lists, is there a documented rule preferring one over the other?

Note, I am not asking about how to indent or display code in a code fence.

  • 4
    Does this answer your question? How do I format my code blocks?, or meta.stackexchange.com/questions/193990/… or meta.stackexchange.com/q/146236/282094
    – Rob
    Commented Apr 6, 2021 at 22:33
  • @Rob No. I am not asking how to display text as code. I'm asking if users prefer one style over the other.
    – Casey
    Commented Apr 6, 2021 at 22:43
  • 7
    Well that would be an opinion based question, which would be off-topic.
    – Luuklag
    Commented Apr 6, 2021 at 22:48
  • Code fences are 'relatively' new (and hinting too - but not as much) so it might also be a matter of how used you are to the old and new ways Commented Apr 6, 2021 at 22:59
  • 4
    @Luuklag "Is there a documented rule preferring one over the other" isn't an opinion-based question. Commented Apr 6, 2021 at 23:01
  • 1
    Rather than reading the first link as "how do I" you should refer to the answer, which suggests that "you should ..." dupe FAQ on MSO. The second link offers two duplicate links in the banner, which offer helpful suggestions. The third link is simply "should it be automated ...", which leads to problems with the code pasted not being equal to the code on the question asker's computer; so you ought to prettify your code before you run it; and copypaste that if you need help.
    – Rob
    Commented Apr 6, 2021 at 23:07
  • 2
    The preference seems to be to fence correctly idented code, sources: meta.stackexchange.com/q/125148/282094 meta.stackoverflow.com/q/388213/3648282 meta.askubuntu.com/q/19300/914627 en.wikipedia.org/wiki/Programming_style
    – Rob
    Commented Apr 7, 2021 at 0:02
  • Parsed more quickly by whom or what? Commented Apr 7, 2021 at 1:18
  • 1
    @P.Mort.-forgotClayShirky_q The proper code highlighting appears faster because the parser doesn't have to guess what language it is.
    – Casey
    Commented Apr 7, 2021 at 1:49
  • Stack Snippets still use html comments for language. If performance was an issue it would make sense they would have been converted. I can't see how parsing a fence vs parsing html comments makes much difference
    – charlietfl
    Commented Apr 7, 2021 at 2:29


Browse other questions tagged .