5

It looks like a while back, the decision was made to convert tabs to spaces in code text (reference). However, today I encountered a problem in a white-space significant language where the user had mixed tabs and spaces inadvertently.

Pasting the user's snippet into my editor, everything worked just fine because the tabs had been converted to spaces. The problem was easy enough to track down, but that's not the issue. To me, it doesn't seem right that SO automatically changes the code that was input. Does anyone else have thoughts on this issue?

5
  • Tabs in source blocks screw everything up, over and over and over. (<flame-on>Not just on SO.</flame-on>) I haven't seen what you're talking about, I just see a mix, which is what screws things up. Commented Aug 15, 2012 at 13:44
  • @DaveNewton -- I personally could not care less about the tabs-vs-spaces debate. (I didn't even realize one existed until I did a quick search to see if this question had been asked before). That said, in some languages, it's a syntax issue, not just a cosmetic issue. And so I don't think that SO should render tabs as 4 spaces (It should render them as tabs). Let the users of SO leave comments as to why tabs in the source code are a bad idea.
    – mgilson
    Commented Aug 15, 2012 at 13:48
  • 1
    OP shouldn't have used tabs in the first place. Spaces FTW! :)
    – PeeHaa
    Commented Aug 15, 2012 at 14:01
  • @mgilson It's rarely a syntax issue, and when it is, it's almost always because there's a mix of tabs and spaces. Makefiles are an example of where it's a legitimate syntax issue; Python shouldn't mix tabs/spaces for precisely this reason. AFAIK tabs are tabs on SO, and when they're mixed, all hell breaks loose in formatting and everyone has to edit them to spaces, so boo. I could care less about tabs-v-spaces, and spaces always wins. Commented Aug 15, 2012 at 14:11
  • So there is absolutely no way to force our code snippets to display tabs instead of spaces? I have an answer on SO with a small code snippet for a config file that only works by using tab characters. I recently noticed that someone complained that my answer wasn't working because I was using spaces instead of tabs but apparently these tab characters are automatically converted and there is nothing I can do to fix this problem! So I added a small warning about replacing these spaces to tab characters but I think this thing is just extremely dumb. Commented Jan 27, 2023 at 21:05

2 Answers 2

3

I've not ever seen tabs being converted to spaces when pasting. The linked MSO question talks about pressing tab while using the editor.

The SO question you link to actually does have embedded tabs in it; the body of the print function starts with a tab, but not the function name itself. The poster must've inadvertently fixed the tab on the def printStats line himself:

enter image description here

The tabs-vs-spaces inconsistencies in Python are a common problem, and Ignacio probably has his answer at the ready in the paste buffer for when these crop up. You can never rely on the OP code samples, they could easily have tinkered with the indentation, not understanding the difference between tabs and spaces anyway. Altering the way tabs are handled won't change that, really.

Actually, come to think about it, the fact that SO renders tabs as 4 spaces is a big hint to the OP something is up, and perhaps some realize their mistake because of this. Let's leave it as it is. :-)

4
  • When I paste the code into emacs or pico, I get 4 spaces in front of def printStats. However, when I look at the actual code posted (by clicking on the edit button), there is clearly a tab in front of def printStats
    – mgilson
    Commented Aug 15, 2012 at 13:34
  • (the first problem isn't in front of print since the AttributeError points to the function itself). Note that this question is about what SO displays, not about the information that is maintained internally.
    – mgilson
    Commented Aug 15, 2012 at 13:36
  • 1
    No, the OP problem was no longer present in the sample he posted because he probably manually removed that tab there, as the editor was showing his code aligned funnily in the preview... Commented Aug 15, 2012 at 13:39
  • Interesting point. I hadn't thought of that. (+1)
    – mgilson
    Commented Aug 15, 2012 at 13:43
3
+50

Please don't change people's code.

If they pasted tabs, render tabs. Or else this makes it hard to reproduce problems when tabs matter.

In particular, this breaks every Makefile code, which requires tabs for the recipe.

Furthermore, this is what CommonMark does: http://spec.commonmark.org/dingus/

1
  • Also, there are CSS options to show the tabs with a size of 4, already used while editing, without actually converting them.
    – Arjan
    Commented Feb 19, 2016 at 6:20

You must log in to answer this question.

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