Whitespace as syntax (was Re: Python Rocks!)

Paul Prescod paul at prescod.net
Tue Feb 8 17:33:55 CET 2000

fcahoon at my-deja.com wrote:
> ...
> Suppose that I'm one of those set-tabs-to-logical-indentation sorts of
> guys, so I set my tab width to 4, then look at this code in my editor.
> Gee, it sure _looks_ like statement4 belongs to "if condition1"!  And,
> if I convert tabs to spaces when I save, statement4 _will_ belong to "if
> condtion1".  I've just unwittingly changed the logic of the code!
> You may, of course, argue that this is unlikely, but it is still
> plausible enough to make me _very_ nervous.

Yes, there is a one in 10,000 chance that a mistake in your usage of the
editor could coincide with this design feature of the Python language.
As long as you only mix spaces and tabs in one or two places in the
module, you might even get your code to run.

But you are a professional programmer. You know that errors happen. Any
C programmer has a long list in his/her head of "things I've done in the
past that really bit me in the ass that I should never do again". Java
programmers have another list. Perl programmers have another one. In
Python, one of them is: "don't mix spaces and tabs." Luckily, this is
much easier to explain than "don't return a pointer to a local variable
because it will be destroyed when the stack pointer changes.".

At the point where a single one of these rare and admittedly unlikely
difficulties elevates itself to a reason not to use an entire language,
we have crossed from the realm of rationality into superstition. Before
you talked to us, you probably didn't understand how rare and unlikely
it is to make syntactically correct Python code that works differently
based on the interpretation of tab stops, nor how easy it is to avoid.

Now you know. Please apply some perspective and cost/benefit analysis.

 Paul Prescod  - ISOGEN Consulting Engineer speaking for himself
"If I say something, yet it does not fill you with the immediate
burning desire to voluntarily show it to everyone you know, well then,
it's probably not all that important."
    - http://www.bespoke.org/viridian/

More information about the Python-list mailing list