4

Why are tabs replaced by spaces in the output when I type them inside of code fences?

Here I used tabs:

int func()
{
    somecode;
}

But you see spaces.

9
  • 14
    Because spaces are the superiour type of whitespace. It's even in the name, noone calls it whitetab.
    – ivarni
    Commented Jul 22, 2020 at 11:03
  • 3
    Useless tabs/spaces flamewar aside, SE has always interpreted 1 tab as 4 spaces, but I've never found any explanation to why. People still ask about languages like Makefile (where tabs are mandatory) and Whitespace (where spaces and tabs make commands) and that doesn't seem to cause much of a problem. Could of curse involve source copy-pasta, but iDunno. Commented Jul 22, 2020 at 11:29
  • 1
    While I don't know the reason, tabs on code block are not reliable. I've seen tables using tabs and code block, and some columns are not aligned.
    – Andrew T.
    Commented Jul 22, 2020 at 11:30
  • @AndrewT. Using tabs for alignment is wrong idea, and here is better to use spaces. And when indenting, you can use both tabs or spaces, but when using tabs user on other side can scale your code, and see it in his familiar look.
    – Gordem
    Commented Jul 22, 2020 at 11:38
  • 3
    Stack Overflow is aligned with Douglas Crockford. Commented Jul 22, 2020 at 11:54
  • 2
    @Zoe I think this was discussed before, see Why does MCVE page instruct users not to use tabs?
    – gnat
    Commented Jul 22, 2020 at 12:17
  • 1
    How exactly did you type a tab into the textarea? You copy/pasted the code from somewhere else, right? Because try as I might, I can't type tabs into a HTML textarea, their default behavior is to tab to the next selectable element in the page. That to me is already a reason to discourage using tabs in code when posting it on Stack Overflow.
    – Gimby
    Commented Jul 23, 2020 at 13:14
  • @Gimby I copy-paste code, or copying only one tab into buffer, and pasting it where I need.
    – Gordem
    Commented Jul 23, 2020 at 14:56
  • 4
    Python users might particularly consider this a bug, because in Python, tabs and spaces are not syntactically identical. Fairly often we get questions about IndentationErrors that potential answerers can't replicate, because the error occurs with the asker's original indentation, but not with the indentation of the post-replacement SO code block.
    – Kevin
    Commented Jul 23, 2020 at 16:09

0

You must log in to answer this question.

Browse other questions tagged .