A Suggestion for Python Colon Syntax
William Djaja Tjokroaminata
billtj at y.glue.umd.edu
Fri Dec 22 13:42:11 EST 2000
Tim Peters <tim.one at home.com> wrote:
: [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.
Exactly. I just regretted the initial study that used newbies and they
preferred colons. At the present time, correct me if I am wrong, I think
it is still rare that Python is one's first programming language. People
who start to use Python may already use some other popular programming
languages. Probably if we do another survey now, the result may be
different. I don't think survey is a bad thing. Richard Stallman
sometimes asked opinions on the emacs newsgroup before he decided whether
to go one way or the other.
:> 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).
Probably it was true a long time ago, a decade perhaps. Nowadays, there
are more programming languages around. In particular, I like the idea of
the basic syntax of Tcl. Yes, it is very simple, and too simple in a lot
of cases (thank goodness that Python syntax is not as simple as Tcl), but
it makes it just requires the bare minimum for syntax. It seems to me
that the colon is redundant, because the next-level indentation is
required afterwards. Isn't it the basic premise of Python to take the
best features of other programming languages? Probably a decade ago ABC
was around, but now I think many more people have encountered Tcl rather
than ABC.
:> 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 can see clearly the big difference (as I have experienced) between using
indentation and curly braces; it makes really consistent coding
style. However, I don't see the colons as falling into the same
category. Yes, Guido wants everybody to use colons at the end of the
clauses, but right now what prevents someone to put semicolon at the end
of every statement? Just compare the two or three formats:
xxxx xxxx xxxx:
xxxx xxxx xxxx
xxxx xxxx xxxx
xxxx xxxx xxxx:
xxxx xxxx xxxx;
xxxx xxxx xxxx;
xxxx xxxx xxxx
xxxx xxxx xxxx
xxxx xxxx xxxx
Which one do you think is the most consistent in layout? To me, it is not
the first one.
:> ...
:> 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.
But the semicolon at the end of the statement break the Pythonic rule.
:> 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).
I am not too familiar with the parsing stuff. However, in my simplistic
opinion, Python is not a free-form language like C or Perl. Therefore,
probably it is reasonable for any parser to breaks a Python code first
into lines, even in backward parsing, instead of parsing it token by
token first. In parsing backwards, can then it just detect first that the
line is at different indentation level rather than try to detect the
colon?
Regards,
Bill
More information about the Python-list
mailing list