Tabs vs Spaces

Doran Barton fozz at iodynamics.com
Sat Nov 4 21:47:12 MST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Steve wrote:
> Just got a bit of a critque on my coding style.
> I realize this has been debated ad-nausem, but does anyone know the
> origin of the tabs vs spaces debate?  I mean seems to me hitting TAB a
> single time is alot easier than hitting the space bar multiple times,
> but I also know there are editors that will convert tabs to spaces and
> vice versa.
> Is there maybe a standard set somewhere on this?  Was there ever a
> standard?

I like and practice what Damian Conway, author of Perl Best Practices writes
about this in the book:

Tabs are a bad choice for indenting code, even if you set your editor's
tabspacing to four columns. Tabs do not appear the same when printed on
different output devices, or pasted into a word-processor document, or even
just viewed in someone else's differently tabspaced editor. So don't use tabs
alone or (worse still) intermix tabs with spaces.

The only reliable, repeatable, transportable way to ensure that indentation
remains consistent across viewing environments is to indent your code using
only spaces.

[...]

Note that this rule *doesn't* mean you can't use the Tab key to indent your
code; only that the result of pressing that key can't actually be a tab.
That's usually very easy to do under modern editors, most of which can easily
be configured to convert tabs to spaces. For example, if you use vim, you can
include the following directives in your .vimrc file:

	set tabstop=4	"An indentation every four columns"
	set expandtab	"Convert all tabs typed into spaces"
	set shiftwidth=4 "Indent/outdent by four columns"
	set shiftround	"Always indent/outdent to the nearest tabstop"

- --
fozz at iodynamics.com is Doran L. Barton, president/CTO, Iodynamics LLC
Iodynamics: IT and Web services by Linux/Open Source specialists
 "After you vomit, you rinse your mouse and if you can eat, eat. "
    -- From a Japanese guide for pregnant women
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFFTWzQfSztmbgzr0ERAo/RAKDGbVXLVmgFJ5Xy1gKHik9M4IV8KACeN5lF
YTEp9Nr7MSyFJtRKZh9eTU8=
=2s+q
-----END PGP SIGNATURE-----



More information about the PLUG mailing list