Indenting with tabs vs spaces

David Bolen db3l at fitlinxx.com
Thu Nov 22 00:32:05 EST 2001


"Peoter Veili" <peoter_veliki at hotmail.com> writes:

> > >Tabs are wrong, because different editors will treat them differently.
> > >
> > >Spaces are right, because a space is a space is a space, everywhere you
> > >go.
> 
> Indenting with tabs can be done such that it will look the same on every
> editor that uses fixed-width fonts, meaning everything will line up
> correctly, it least in the sense that really matters.

Um, that's only true if your visual display uses the same indentation
for tabs as someone else's.  E.g., if your fixed-width editor has "tab
stops" at 4 spaces, and someone else's has it at 8, then obviously
what lines up on yoru screen won't on theirs and vice versa.  It just
gets worse if you include a mixture of tabs and spaces, since then it
probably won't even be aligned in general on the other system.

The above only works if you both agree on the visual display of the
tab character.

> Besides this I know of no problems with using tabs.  I find them
> cleaner and more efficient.  I'd rather tab 10 times than hit the

If only we could all agree on how tabs in a file should be displayed
there wouldn't be a problem (technically, there's no parser problem
anyway it's all visual but then that's part of coding).  But clearly
as past discussions have shown we can't, so the general rule of
sticking with spaces makes it easier for everyone to see the same
visual representation of source.

Your example code is a good example - it showed up in my newsreader
(fixed font) as:

    function helloThere("hello",
                                       "there"){
    }

so I'm not quite sure what it was supposed to look like, but I expect
it certainly didn't look like that on your screen :-)

> cleaner and more efficient.  I'd rather tab 10 times than hit the
> space bar 40 times. I never have to go through a whole file and
> manually line things up because at one place in the file I
> accidentally didn't indent with the right amount of spaces and half
> the file needs fixing.  Auto-indent helps, but still....

As someone else pointed out, we do need to keep distinct the concept
of pressing the tab key, and using a tab character within the source.
There are many ways to minimize input while not requiring hard tabs in
the source.  There's absolutely nothing wrong with using the tab key
to indicate that you want some sort of logical indentation, but it's
probably best if the tool decides to do it with spaces.

For example, Python mode in emacs will auto-indent a line on tab, but
if it guesses wrong, a single backspace will step back a full
indentation level (4 spaces) so it can still be very efficient to key
in even though spaces are being used.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list