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

Derrick 'dman' Hudson dman@dman.ddts.net
Sat Feb 15 16:26:03 2003


--cWoXeonUoKmBZSoM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Feb 15, 2003 at 12:03:46PM -0500, Paul Tremblay wrote:
| Sorry if this question causes an endless debate=20

What endless debate?  Use spaces and all will be good.  :-).

| I want to know if I should use tabs or spaces when indenting.

Spaces.  Always.  (except in Makefiles, but they're evil anyways ;-))

| I use vim, and have been using the autoindent feature. If I type

Good.

| if var=3D=3D5:
|=20
| then vim atomatically inserts a tab of 8 spaces for the next line:

Sorta.  If 'et' is false, vim inserts a combination of tabs and spaces
such that the indentation level is n*'shiftwidth' (where n is the
current level of indentation).

| if var=3D=3D5:
| 	pass #do something
|=20
| However, 8 spaces is quite a bit of space.

I agree.

| To improve the excessive space problem, I told vim to change the
| amount of space in a tab from 8 to 5.=20

Wrong solution, see below.

| I then ran a script and found I got a strange out of index message which
| I had already checked for. It turns out that vim had screwed up the
| indenting so that what had been part of an 'if' statment was no longer
| part of it.=20

vim did what it was told to do.  However, python (and some other
equipment, both software and hardware) read a tab as equivalent to 8
spaces.  Don't try to change this.  Instead use spaces where you want
a different spacing level.

| Because of this, I am suddenly inclined towards spaces. I plan to
| distribue my module, and I see that tabs could cause the whole thing to
| break.

Yep.

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

Guido did :
    http://www.python.org/peps/pep-0008.html

    Never mix tabs and spaces.  The most popular way of indenting
    Python is with spaces only.

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

All the goodies are here :
    http://dman.ddts.net/~dman/config_docs/dot-vimrc

In short:

augroup Python
    au!
    au FileType python set sts=3D5 sw=3D5 et ts=3D8 ai si cin tw=3D78 fo=3D=
croq2 hls

    au FileType python set comments=3Db:#=20
    " override C preprocessor indenting
    au FileType python inoremap # X<C-H>#
augroup END


-D

--=20
A perverse man stirs up dissension,
and a gossip separates close friends.
        Proverbs 16:28
=20
http://dman.ddts.net/~dman/

--cWoXeonUoKmBZSoM
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj5OsEEACgkQO8l8XBKTpRTtXwCfe3DKWNJMRH+TKeJleC+4nDq2
K3IAoI/vfAAVxabQ5P2YqCFluSF3ujcZ
=SZpv
-----END PGP SIGNATURE-----

--cWoXeonUoKmBZSoM--