[Python-ideas] Making colons optional?
yaogzhan at gmail.com
Thu Feb 5 19:12:58 CET 2009
On 5-Feb-09, at 7:31 AM, Steven D'Aprano wrote:
> Riobard Zhan wrote:
>> - I noticed a strong tendency to forget colons by new users of
>> Python in a second-year computer science undergraduate course. The
>> students seemed not getting used to colons even near the end of the
>> course. I guess it is probably because they learn Java and C first,
>> both of which do not have colons. What other languages do you know
>> that require colons?
> Pascal uses colons, but not for the exact same purpose as Python.
> Both languages use colons in similar ways to it's use in English. In
> particular, Python uses colons as a break between clauses: larger
> than a comma, smaller than a period.
Pascal is my first language. It has been some years ago, so I cannot
remember the detail now. I checked wikipedia and did not find colons
are used after if's. Not sure if you mean declarations? If so, I don't
think that is what we are discussing here; Java and C also use colons
in switch/case statements. AFAIK, Python is quite unique in requiring
trailing colons after if's, for's, and function/class definitions.
>> - I find colons pretty annoying.
> I'm sorry you dislike colons, but I like them.
Yes I agree with you that many people like colons. What bothers me is
that some people dislike them, but not given the choice to avoid them.
We don't like semicolons in Python, but what would stop a hard-core C
users to end every statement with a semicolon? They have the choice.
And I would also argue that many of those like colons not because they
really feel colons improve readability, but that they have get used to
colons in the first place. You like colons, I don't. How do you know
another Python user will like them or not? By making trailing colons
OPTIONAL, we can probably have the chance to field test. If people
really think colons improve readability that much, they can still use
them, just like we feel semicolons are line noise and void them if
possible, even though we CAN use them. I don't think we will ever lose
anything to make colons optional.
>> - What problems do you think will occur if colons are made optional?
> I don't think it would lead to any problems, but I think it would
> make Python less elegant.
I think omitting colons makes Python more elegant--more uniform, less
clutter. It's an itch every time I see a piece of Ruby code with lots
of def's and if's without trailing colons ...
More information about the Python-ideas