17

Looking at the mvce page, I notice that it instructs users not to use tabs when posting a question. It claims that they make a mess on Stack Overflow, but I don't understand what problems tabs cause. I admit that tabs sometimes cause heavily indented code to be too wide, but if that is the only motivation, I would rather tell users something like "where possible, avoid horizontal scrolling."

https://stackoverflow.com/help/mcve

Readable

Make your code easily readable by using consistent naming and indentation. This will allow you to identify mistakes more quickly, and make it easier for people to understand the code example in your question. Most code editors have a shortcut for formatting the code - find it, and use it! Also, don't use tabs - they may look good in your editor, but they'll just make a mess on Stack Overflow.

3
  • It's just that it's way easier to format code with spaces in the editor. Commented Feb 25, 2014 at 21:24
  • @HugoDozois: Maybe so, but that's not really a concern for readability. MVCE is about making answerers happy; fighting with the editor is a problem for the asker to resolve. I think it's common for users to type their MVCE code into their editor and paste it into SO (in fact, the MVCE page pushes users towards doing so in the "Tested" section). In that scenario, I don't really mind if the user uses tabs instead of spaces.
    – Brian
    Commented Feb 25, 2014 at 21:28
  • Well most users that tried to format code with tabs that I've seen horribly failed and that does not help to make it readable. The code editor of SO is just not made for tabs, and they do not render exactly in the same way as spaces do. Commented Feb 25, 2014 at 21:41

1 Answer 1

12

In my experience, code indented with tabs looks just fine on SO, as long as it uses only tabs for indentation.

Where things get messy is with code that mixes spaces and tabs for indentation, and the reason for this is inconsistent tab depth. In particular:

  • The SO Markdown renderer uses a 4-column tab depth. Also, the leading whitespace stripped from indented code blocks is either one tab or 4 spaces.

  • The tab depth for the edit box where you compose your post depends on your browser, but is most commonly 8 columns.

  • The tab depth in your editor / IDE might be anything from 2 to 8 columns or more.

Thus, for example,

    these lines
        are aligned
            in the edit box (at least in Chrome),

whereas

    these lines
    are aligned
    in the post (but not in the edit box).

Hilarity messy confusion ensues.


Update: It seems that, since I originally wrote this answer, the SO style sheet was updated to specify a 4-column tab size for the edit box. Thus, at least in browsers that support this feature (currently at least Chrome, Firefox, Opera and Safari, but not IE), this problem should be mostly gone.

It might make sense to update the MCVE page in light of this change. On the other hand, browser support for this feature is still not ubiquitous, and of course things can still break if someone pastes code using a mix of tabs and spaces from an editor using a different tab spacing, and doesn't check that the result looks right. Thus, avoiding tabs may still be good advice for new users, even if it's not as critical as it used to be.

4
  • 7
    In IE10's edit box, tabs are a ridiculous ten columns. Commented Feb 25, 2014 at 22:10
  • A valid point, and an easy mistake to make when tweaking code in the edit box. I would still rather tell users to check their post in the preview box. That will catch broken indentation and horizontal width issues. Personally, I always check for horizontal scrolling in the preview box; I think that's just as annoying as broken indentation.
    – Brian
    Commented Feb 25, 2014 at 22:25
  • As an experienced user I don't particularly like this advice. However, it's mostly newer users who get sent to that page, so the advice is not unreasonable. Accepted.
    – Brian
    Commented Feb 27, 2014 at 21:20
  • 5
    Tabs are still an abomination. I mean, power user abomination. I mean feature. Abomination.
    – Shog9
    Commented Dec 16, 2015 at 5:03

You must log in to answer this question.

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