Spaces and tabs in Python

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

Indention in Python -- what do you use?

Spaces for most projects
17
30%
Tabs for most projects
38
67%
It's a mess, different from file to file (or worse)
2
4%
 
Total votes: 57

User avatar
enk
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark
Contact:

Spaces and tabs in Python

Postby enk » Thu Apr 08, 2010 12:00 am UTC

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.
phlip wrote:Ha HA! Recycled emacs jokes.

mouseposture
Posts: 42
Joined: Tue Sep 15, 2009 2:42 am UTC

Re: Spaces and tabs in Python

Postby mouseposture » Thu Apr 08, 2010 12:46 am UTC

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.

Alexander The 1st
Posts: 44
Joined: Fri Apr 17, 2009 10:47 pm UTC
Contact:

Re: Spaces and tabs in Python

Postby Alexander The 1st » Thu Apr 08, 2010 5:28 am UTC

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.
...YOU DIDN'T SEE ANYTHING...

User avatar
Aaeriele
Posts: 2127
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Spaces and tabs in Python

Postby Aaeriele » Tue Apr 13, 2010 9:21 am UTC

Spaces.
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!

User avatar
Levi
Posts: 1294
Joined: Tue Oct 14, 2008 1:12 am UTC

Re: Spaces and tabs in Python

Postby Levi » Wed Apr 14, 2010 8:57 pm UTC

I use tabs because I can hit tab just once instead of the five times I would have to hit the spacebar.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Spaces and tabs in Python

Postby Berengal » Thu Apr 15, 2010 4:55 am UTC

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.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
Levi
Posts: 1294
Joined: Tue Oct 14, 2008 1:12 am UTC

Re: Spaces and tabs in Python

Postby Levi » Thu Apr 15, 2010 7:43 am UTC

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.

User avatar
GrawSith
Posts: 91
Joined: Fri Dec 28, 2007 2:46 pm UTC
Location: Down-frickin'-under.
Contact:

Re: Spaces and tabs in Python

Postby GrawSith » Tue Apr 20, 2010 8:25 am UTC

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!".

User avatar
phlip
Restorer of Worlds
Posts: 7572
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Spaces and tabs in Python

Postby phlip » Tue Apr 20, 2010 8:45 am UTC

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.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
flying sheep
Posts: 63
Joined: Sun Jan 31, 2010 12:35 am UTC

Re: Spaces and tabs in Python

Postby flying sheep » Mon Apr 26, 2010 12:15 am UTC

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 ;)

User avatar
enk
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark
Contact:

Re: Spaces and tabs in Python

Postby enk » Tue Apr 27, 2010 6:03 pm UTC

I'm suprised about the result of the poll (could use more votes though).

I wonder where all the space-users PEP8 mentions are? :)
phlip wrote:Ha HA! Recycled emacs jokes.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Spaces and tabs in Python

Postby Xeio » Tue Apr 27, 2010 9:31 pm UTC

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

User avatar
Xanthir
My HERO!!!
Posts: 5410
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Spaces and tabs in Python

Postby Xanthir » Thu Apr 29, 2010 4:01 am UTC

I just discovered that the Google coding standard for Python mandates *two* spaces per indent. Wtf?
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

lukesneeringer
Posts: 3
Joined: Fri May 21, 2010 5:25 pm UTC

Re: Spaces and tabs in Python

Postby lukesneeringer » Fri May 21, 2010 7:37 pm UTC

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.

levantis
Posts: 20
Joined: Thu Feb 05, 2009 1:42 pm UTC

Re: Spaces and tabs in Python

Postby levantis » Mon May 24, 2010 3:55 pm UTC

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.

User avatar
Durinthal
Posts: 799
Joined: Mon Dec 11, 2006 9:46 pm UTC
Location: 127.0.0.1

Re: Spaces and tabs in Python

Postby Durinthal » Sun Jun 06, 2010 5:35 pm UTC

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.


Return to “Religious Wars”

Who is online

Users browsing this forum: No registered users and 3 guests