A Suggestion for Python Colon Syntax

Tim Peters tim.one at home.com
Thu Dec 21 19:53:52 EST 2000


[William Djaja Tjokroaminata]
> I saw many replies that give the reasons why the colons are
> *needed*.

Not mine:  it told you why the colons are *there*.  It's a human-factors
thing, not a tech thing.  Desirable, not necessary.

> My suggestion is to make it *optional*, like the semicolon at
> the end of statements.

Understood.  Won't happen, though:  Python has been around for a decade.  Do
you imagine that Guido hasn't heard this suggestion before?  In fact there
are very few "new syntax" ideas that weren't debated and rejected before
1991 ended.  And, yes, this is one of them (ditto the whole "while 1" thread
that's been going on virtually non-stop for a decade).

> Yes, for people who cares about making it easier to read for newbies,
> they can always put colons.  Yes, for people who use emacs to
> automatically indent the next line, they can put colons too.

Guido abhors gratuitous variations in coding sytle; that's largely why
indentation is used instead of curly braces or begin/end to begin with.  A
choice about whether or not to use a colon is simply not something people
*need*.  The few places Python allows gratuitous choices today are places
Guido regrets (although not enough to lose sleep over <wink>).  For example,
Guido is unhappy that both "<>" and "!=" are accepted to mean "not equal";
the older "<>" survives only for compatibility with a very early release of
the language.

> ...
> I want opinion of you who have programmed for a long time whether
> there will be some harms if the colons are made optional.

It's Pythonic to either always require them or never allow them; the former
won 10 years ago.

> If not, probably someone can tell me how I can forward this
> suggestion to the core Python development team?

You already did <wink> -- Guido's on vacation this week, which makes me as
close as you'll get until after Christmas.  You can submit a formal feature
request via the SourceForge bug manager at:

    http://sourceforge.net/bugs/?group_id=5470

but you should expect it to be rejected.  Besides that Guido will object on
principle, the practical support costs of adding such a thing are enormous:
editing environments from the Emacs Python mode to IDLE would be broken, and
would be difficult to fix.  For a hint as to why it's difficult, study
tokenize.py in the std library.  That trailing colon makes partial parsing a
whole lot easier, and especially when parsing backwards (as e.g. the Emacs
python-mode and IDLE and PythonWin need to do routinely).

    if  (a,
         b,
         c) != \
        (d,
         e,
         f)
        (a,
         b,
         c) = \
        (d,
         e,
         f)
ly y'rs  - tim





More information about the Python-list mailing list