What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 133 Stack Exchange communities.

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?

share|improve this question
    
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. –  Dave Newton Aug 15 '12 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 Aug 15 '12 at 13:48
1  
OP shouldn't have used tabs in the first place. Spaces FTW! :) –  PeeHaa Aug 15 '12 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. –  Dave Newton Aug 15 '12 at 14:11

1 Answer 1

up vote 3 down vote accepted

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. :-)

share|improve this answer
    
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 Aug 15 '12 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 Aug 15 '12 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... –  Martijn Pieters Aug 15 '12 at 13:39
    
Interesting point. I hadn't thought of that. (+1) –  mgilson Aug 15 '12 at 13:43

You must log in to answer this question.

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