Page 1 of 1

Spaces and tabs in Python

Posted: Thu Apr 08, 2010 12:00 am UTC
by enk
Oh, hi.

This is not a generic spaces vs. tabs thread, we already have one of those.

And Python itself has a PEP 8, stating among other things:

Never mix tabs and spaces. The most popular way of indenting Python is with spaces only. The second-most popular way is with tabs only. [...] For new projects, spaces-only are strongly recommended over tabs.


I'd just like to know.. what do you people usually use IRL? Including what you're subjected to in projects where you don't make the decision.

Re: Spaces and tabs in Python

Posted: Thu Apr 08, 2010 12:46 am UTC
by mouseposture
I used to use tabs for nesting, spaces for alignment, but my IDE complained, so I switched to all-spaces.

I decided I didn't like 8-spaces per level indenting so I had the editor change it to 4. However, the diff between the current revision and the previous one now shows changes on every indented (= virtually every) line. That change should have been purely cosmetic, like changing the syntax-coloring conventions in the editor, but instead, my revision control system thinks I changed nearly every line.

In Python, where indentation has separate effects on appearance and meaning, using tabs for indentation would have let me keep those two things distinct.

Re: Spaces and tabs in Python

Posted: Thu Apr 08, 2010 5:28 am UTC
by Alexander The 1st
Tabs only. Spaces are difficult to ensure proper indentation, and I do want to be able to compile the code as quickly as possible, without having to go back and fix indentation because "it's inconsistent".

As for alignment, I just let go Candian close - if it's off by one or two [tabs are four/five, depending on how IDLE handles it by default] spaces, it's good enough.

Identation errors prevent compilation - alignment only makes something seem indented for a second, until you realise it's not truly indented 5 in - then it becomes clear that it's just more of the parameters/etc. in the function.

Re: Spaces and tabs in Python

Posted: Tue Apr 13, 2010 9:21 am UTC
by Aaeriele
Spaces.

Re: Spaces and tabs in Python

Posted: Wed Apr 14, 2010 8:57 pm UTC
by Levi
I use tabs because I can hit tab just once instead of the five times I would have to hit the spacebar.

Re: Spaces and tabs in Python

Posted: Thu Apr 15, 2010 4:55 am UTC
by Berengal
Levi wrote:I use tabs because I can hit tab just once instead of the five times I would have to hit the spacebar.

I use the tab button to insert spaces for indentation because anything else would be stupidity.

Re: Spaces and tabs in Python

Posted: Thu Apr 15, 2010 7:43 am UTC
by Levi
Berengal wrote:
Levi wrote:I use tabs because I can hit tab just once instead of the five times I would have to hit the spacebar.

I use the tab button to insert spaces for indentation because anything else would be stupidity.

Yeah, my editor sticks spaces in when I hit tab.

Re: Spaces and tabs in Python

Posted: Tue Apr 20, 2010 8:25 am UTC
by GrawSith
In an environment where you have a choice between hard-tabs (actual tab characters "\t") or soft-tabs (space space space space), I go with hard-tabs. Spaces just weird me out, i'm constantly thinking "this is why we invented the tab key!".

Re: Spaces and tabs in Python

Posted: Tue Apr 20, 2010 8:45 am UTC
by phlip
Seriously. Tabs for indenting, spaces for alignment... I don't care what the language is, that's just what makes sense.

The people who wrote PEP 8 have brain worms.

Re: Spaces and tabs in Python

Posted: Mon Apr 26, 2010 12:15 am UTC
by flying sheep
1 tab per indentation level.
that’s what tabs are for.

Levi wrote:
Berengal wrote:Yeah, my editor sticks spaces in when I hit tab.
i think that’s just misconfiguration. you don’t have to file a bug report ;)

Re: Spaces and tabs in Python

Posted: Tue Apr 27, 2010 6:03 pm UTC
by enk
I'm suprised about the result of the poll (could use more votes though).

I wonder where all the space-users PEP8 mentions are? :)

Re: Spaces and tabs in Python

Posted: Tue Apr 27, 2010 9:31 pm UTC
by Xeio
Spaces, but I type tabs. Any good IDE will automatically convert tabs to a set number of spaces (which can usually be configured). Generally set to 4 spaces per tab (though I use 2 more often in scripting languages like python for whatever reason...).

Though, I prefer avoiding whitespace significant languages...

Re: Spaces and tabs in Python

Posted: Thu Apr 29, 2010 4:01 am UTC
by Xanthir
I just discovered that the Google coding standard for Python mandates *two* spaces per indent. Wtf?

Re: Spaces and tabs in Python

Posted: Fri May 21, 2010 7:37 pm UTC
by lukesneeringer
I use spaces (because of PEP 8). I would vastly prefer to use tabs, personally. I actually did use them until my co-worker found PEP 8 and we changed our entire codebase to be spaces.

Re: Spaces and tabs in Python

Posted: Mon May 24, 2010 3:55 pm UTC
by levantis
Tabs and only tabs. I had plety of trouble copypasting C code together that contained IDE-made spaces, because someone liked 3, someone 4, someone 5. the code looked really ugly. Python would complain about it. When using tabs, you can always copy anyone`s code, but set the tabs to look as any umber of spaces as you like. And the compiler won`t make error messages because of inconsistent indentation.

Re: Spaces and tabs in Python

Posted: Sun Jun 06, 2010 5:35 pm UTC
by Durinthal
4-space tabs, automatically converted to spaces in my editor. I actually did it that way before I discovered PEP8 as well, so I was pleasantly surprised.