Tabs and spaces (style)

Alex Martelli aleaxit at yahoo.com
Wed May 2 07:26:28 EDT 2001


"Cantanker" <az at cantanker.net.nospam> wrote in message
news:mBKH6.3793$VM5.125017 at ozemail.com.au...
> In article <4jhuet4uvf8a08i017u0jf9n37lhv7aih6 at 4ax.com>, "Courageous"
> <jkraska1 at san.rr.com> wrote:
>
> Sorry to sound like a broken record, but I had to bite.
>
> > Because of the never-ending "what tab indentation level to use" wars, on
> > my projects I forbid tabs in Python files outright.
>
> Your actions are inconsistent with your reasoning. If there is a
> never-ending war, why enforce an action that only serves to fan flames?
>
> Alex Martelli uses spaces "so _all_ tools will certainly see my source in
just
> the same way", which is another way of saying "to impose my choice of
> tab/indent size on _everyone_ else". If you instead use tabs, _everyone_
> has the choice of what tabsize to use (assuming they use a real editor :)

Why would "an editor" ("real", or otherwise) be the ONLY tool you
ever need to run on Python source files?  If you only use tabs, no
spaces, you run into problems when a tool uses an inappropriate
tabsize -- say 0 for Outlook Express, 8 m-spaces for a printer (so
that printed code "runs off the right" of the paper), and so on.
Mixes of tabs and spaces encounter similar and harder problems.

If one could _assume_ that some tool able to interpret leading
whitespace as desired was always in use, then it would make no
real difference, either way, how the leading whitespace is stored
on disk.  The opposite assumption, that tools of all sorts, with
no ability for configuration and widely varying interpretation of
tabs, can be used directly, makes the presence of tabs a bother.

The only set of assumptions I can see, where tabs may be better
than spaces, is when some tool IS assumed to be involved, which
has the ability to interpret tabs but NOT the ability to interpret
and reformat leading whitespace that is not encoded as tabs.  Why
wouldn't a "real editor" (VIM, EMACS, many others besides) not be
just as able to interpret any leading whitespace as you, wish, as
to interpret just tabs?

Assuming that some SUITABLE tool is always interposed when your
source is viewed/used in any way is a rather large assumption and
fails in practice any time shared filesystems, copy-and-paste
posting of sources, etc, occurs.  Many people are apparently not
aware of such situations, or do not care a whit about readers who
are in such situations, and thus I often find myself having to
guess where the indents are meant to go, as no indent at all is
being shown to me (0-space interpretation of tabs by OE, etc).

And similarly when, for example, code is being entered directly
into an HTML text area -- Tab is then normally interpreted as
"take me to the next field", and Spaces are needed to actually
enter the indent.  Doesn't everybody contribute to the Cookbook,
enter bug-reports on HTML forms, etc, etc?

Using spaces-only ensures against such "no indentation at all
being shown" disasters, and of course it does not hamper at all
readers who "use a real editor" -- far from imposing my choice
of indent size (tab size clearly doesn't enter the issue...),
it will of course be trivially easy for the (e.g.) VIM or EMACS
user to have his or her favorite editor automatically massage
leading whitespace in whatever form it comes.


> I'm sorry to sound so stubborn, it's something that I'm quite touchy
> with. I'm sure you're all good coders. :)

Coding skill doesn't seem very relevant to me here, but general
design and analysis skills might be.  And of course, your own
stubborness will be equally matched by those of us to whom the
use of tab-indented sources (e.g. in posts) means having to
divine where the indents are meant to go in snippets which are
shown to us as, e.g.:

while a condition:
some code here
if something else:
a few more lines
if another condition:
and so on
else:
and so forth

I see no comparably disasterous situation for spaces-only, nor
does it seem to me to be reasonable to insist I cannot use a
widespread newsreading tool just because some people insist on
posting tabs-indented source.  Clearly, then, no consensus will
ever be built, as long as tools exists and are used that just
can't handle tab-indented sources sensibly, FOR tabs and against
spaces-only.  Apparently, no consensus to eschew tabs is possible
either (given the "so stubborn ... quite touchy" position of
some -- despite the lack of equally-disasterous counter-cases,
as far as I know).

If no side can ever possibly give in to the other (because it
would mean having to drop many important tools, in one case;
because of stubborness, touchiness, or whatever else, in the
other) then no consensus will ever exist, period.


Alex






More information about the Python-list mailing list