3

the MCVE help page advises people not to use tabs when asking questions.

Also, don't use tabs - they may look good in your editor, but they'll just make a mess on Stack Overflow.

There's a standing feature request to add a similar warning to the editing help page.

But does this warning make sense in the first place? Stack Overflow renders tabs and spaces identically. The problem, I guess, is just that they don't mix well. With this in mind, wouldn't it make more sense to just tell people to double-check their code alignment in the preview area?

3
  • 4
    Editing mixed-up posts is really a pain (pretty much have to resort to an external editor). (But people who produce horribly mixed-up code dumps are, unfortunately, people who wouldn't have read that page anyway...)
    – Mat
    May 21, 2014 at 8:57
  • 1
    Mixing tabs and spaces renders fine (sandbox example] but indeed editing such posts is annoying.
    – user247702
    May 21, 2014 at 9:00
  • I'm always annoyed when I want to type code and hit tab and it doesn't work. Typing spaces is annoying. May 21, 2014 at 9:55

1 Answer 1

4

But does this warning make sense in the first place?

Yes, absolutely, it does make sense in the first place!

In some languages indentation has semantic force. (Python, for instance.) I have run into questions where the OP mixed tabs and spaces. In one case, when the question was viewed normally, it appeared to do the right thing, and indeed the question had accumulated a few upvoted comments saying "your code looks correct". In edit mode, the mixture of spaces and tab revealed a scenario consistent with the problem the OP was reporting.

Even in languages that don't give semantic force to indentation, the mixture of spaces and tabs is unlikely to render in the way the OP meant it to render. Again, I've seen this happen in questions posted on SO.

With this in mind, wouldn't it make more sense to just tell people to double-check their code alignment in the preview area?

"Don't use tabs" is better advice, because the issue is not just how it looks on SO. The issue is how it looks in any other editing environment than the one the OP uses. The issue is also how people who'd collaborate with the OP (either on SO or elsewhere) would have the pain of dealing with a mixture of tabs and spaces.

8
  • "don't use tabs" will mean to a significant number of users their SO instructions are: "copy your tab indented source code from the editor into SO tediously replace all tabs with spaces then click the {} button to 4 space indent the text as a code block". I'm by no means pro mixed whitespace - Why can't e.g. tabs be replaced by 4 spaces on saving? Much simpler.
    – AD7six
    May 21, 2014 at 11:13
  • Editors have settings that allow users to set tabs to be equivalent to 2 spaces or 8 spaces or whatever. (Emacs' tab-width is 8 by default.) An automatic conversion might produce the right result but, then again, it might not. If a significant number of SO users are inconvenienced by this (which I doubt), then it is a good thing because they should get rid of this appalling practice.
    – Louis
    May 21, 2014 at 11:21
  • Are you sure you want to turn this question into a (source code) tab v spaces debate? That's not the question (is it???) and not going to be productive for anyone.
    – AD7six
    May 21, 2014 at 11:29
  • 1
    @AD7six You can't just convert them to 4 spaces, because that's not what a tab is. Just because it's often used to look like four spaces doesn't mean everyone does that. A tab, by definition, is a character that represents anywhere from 1 to 8 spaces. So the user does have to do this on their own.
    – animuson StaffMod
    May 21, 2014 at 12:35
  • @animuson SO renders a tab as four spaces - surely what matters is how the question looks to readers.
    – AD7six
    May 21, 2014 at 12:36
  • 1
    @AD7six SO has nothing to do with it. Browsers generally render it as four. But that's still an assumption based on commonality.
    – animuson StaffMod
    May 21, 2014 at 12:38
  • @animuson are you sure? The tab example linked in the question uses four spaces for the tab-input example, as does the preview below if you input tab-indented code. I.e. It's rendered like this if you use tabs.
    – AD7six
    May 21, 2014 at 12:45
  • Incidentally that's also not true, most browsers render a tab as 8 spaces.
    – AD7six
    May 21, 2014 at 12:51

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