Tabs versus Spaces in Source Code

Chris Klaiber cklaiber at gmail.com
Mon May 15 00:41:01 EDT 2006


On 5/14/06, Edward Elliott <nobody at 127.0.0.1> wrote:
>
> Eli Gottlieb wrote:
>
> > Actually, spaces are better for indenting code.  The exact amount of
> > space taken up by one space character will always (or at least tend to
> > be) the same, while every combination of keyboard driver, operating
> > system, text editor, content/file format, and character encoding all
> > change precisely what the tab key does.
>
> What you see as tabs' weakness is their strength.  They encode '1 level of
> indentation', not a fixed width.  Of course tabs are rendered differently
> by different editors -- that's the point.  If you like indentation to be 2
> or 3 or 7 chars wide, you can view your preference without forcing it on
> the rest of the world.  It's a logical rather than a fixed encoding.


I think the logical encoding argument justifies that tabs are the proper
tool for the job of indentation. For me, the problem is really indentation
of source code and how it conflicts with the historically imposed 80
character line width. When programming, I tend to set my editor window
widths to 80 characters so I know when I'm going over, and my terminals all
default to width 80.

The problem comes when the author prefers a smaller tab width than what my
editor is set to. Sure, I could change it for that file, but what if I'm
reading a whole directory? Sure, I could change the default setting in my
editor, but what if I'm browsing multiple projects in the same day? Sure, I
could find a way to set the tab width based on the directory I'm currently
in, but by now I'm annoyed and simply replacing tabs with spaces is a far
simpler solution that requires zero configuration on my part.

> There's no use in typing "tab" for indentation when my text editor will
> > simply convert it to three spaces, or worse, autoindent and mix tabs
> > with spaces so that I have no idea how many actual whitespace characters
> > of what kinds are really taking up all that whitespace.  I admit it
> > doesn't usually matter, but then you go back to try and make your code
> > prettier and find yourself asking "WTF?"
>
> Sounds like the problem is your editor, not tabs.  But I wouldn't rule out
> PEBCAK either. ;)
>
>
> > Undoubtedly adding the second spark to the holy war,
>
> Undoubtedly.  Let's keep it civil, shall we?  And please limit the
> cross-posting to a minimum.  (directed at the group, not you personally
> Eli).
>
> --
> Edward Elliott
> UC Berkeley School of Law (Boalt Hall)
> complangpython at eddeye dot net
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060515/5047136a/attachment.html>


More information about the Python-list mailing list