[Tutor] tabs or spaces (the endless debate!)

Tim Peters tim.one@comcast.net
Sat Feb 15 12:29:01 2003


[Paul Tremblay]
> ...
> I want to know if I should use tabs or spaces when indenting.

The standard for the Python library is 4 spaces per indent level, and no
hard tab characters period (whether in leading whitespace or comments or
anywhere else).  Tools/scripts/reindent.py rewrites Python source to that
standard, and is routinely run over the Python development tree.

> ...
> So can someone sum up the pros and cons of tabs versus spaces?

For code that will never escape your personal machine, it doesn't matter,
provided only that you never mix tabs with spaces in a single file.  For
distributed code, hard tabs cause needless headaches for people who don't
use exactly the same tools that you use.

> Also, if I do decide on spaces, how do I make vim automatically insert 5
> spaces, rather than a tab space of 8. (I know this is really a vim
> question, but I figure that there are bound to be some vim users who
> know this question cold.)

I'm sure that's so, but I'm not one of them <wink>.  A quick search via
Google suggested that Python vim users do

    :set expandtab tabstop=4 shiftwidth=4

but it's all gibberish to me.