Python Rocks! - get rid of colons

Tim Peters tim_one at email.msn.com
Wed Jan 19 23:54:00 EST 2000


[Sposhua]
> I'm one of the "prefers indentation to {}" ppl, and I'd
> just like to add: whe the heck do we need colons (:) at
> the end of if's 'n loops anyway?  The only loss I see is
> to these 1-liners:
>
> if a==b: eric=idle
>
> What's wrong with:
>
> if a==b
> 	eric=idle

As Michael Hudson said, the connection between colons and blocks was adopted
from Python's closest predecessor, ABC.  Formal usability studies showed
that while indentation was less confusing than assorted bracketing
constructs to newbies, the combination of indentation and an introductory
colon was even better.  You're right that the grammar has little use for it;
although, pragmatically, it's a great aid to semi-stupid tools (like Python
editor modes -- not to mention all us Python programmers <wink>).

> (oh, and wouln't it make life easier to change == to = and
> let python work out when it is assingment and when it is
> comparison?)

Before its 1.0 release, Python *did* use "=" for both binding and equality
testing.  It didn't work out well; e.g., picture

>>> x = y

in interactive mode.  It's truly ambiguous (are you trying to bind or test
for equality?).  It was taken to mean binding, and testing for equality
needed to be spelled with parens, like

>>> (x=y)

Ambiguity, and Yet Another Special Meaning for Parens, were taken as bad
omens.  So Guido exorcised those demons.

BTW, you can still find the script that was distributed at the time (to
change equality "=" to "==") in the source distribution, in
Demo/scripts/eqfix.py.  I wrote a script at the same time to do the same
thing, but in Perl.  This had the intended effect of redoubling Guido's
resolve to continue developing Python <wink>.

although-parsing-without-a-parser-is-hokey-in-any-
    language-ly y'rs  - tim






More information about the Python-list mailing list