[Python-ideas] Making colons optional?

Riobard Zhan yaogzhan at gmail.com
Sun Feb 8 07:47:14 CET 2009


On 6-Feb-09, at 3:16 PM, Georg Brandl wrote:

> Riobard Zhan schrieb:
>> 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.
>
> Python is also quite unique in using indentation to delimit blocks,
> so I'm not sure what point you're trying to make.

Sorry, I did not make it obvious. Please let me re-state it more  
clearly.

I pointed out that Python is quite unique in requiring trailing colons  
because I don't think there are any other popular languages do so.  
Therefore I did not understand why you mentioned Pascal. I was trying  
to figure out if you mean Pascal uses colons in declarations.


> I think it's a good indicator for optional syntax if you can formulate
> new rules for PEP 8 that state when to use it.  In the case of colons,
> you'd have to either forbid or mandate them; I'd be at a loss to find
> another consistent rule.  So, making them optional is pointless; we
> should either keep them or remove them.  And removing is out of the
> question.
>
> Applying that indicator to semicolons, there is a clear rule in PEP 8
> that states when to use them: to separate two statements on one line.

I thought semicolons and multiple statements on one line are  
discouraged in PEP 8. Did I miss something? :|


> However, the only person around here whose
> itches alone, in the face of a wall of disagreeing users, can lead to
> a change in the language, is Guido.

Agreed. That's what BDFL means.

I'm not trying to impose my itches on you. I'm not the BDFL. I'm  
explaining why I think omitting colons makes Python more elegant.


> Yes, I have read all those remarks about semicolons.

Thanks very much! I thought you ignored them before. I apologize :)


>    What you all fail to recognize is that the majority of Python users
>    like the colons, and wouldn't program without them.

I doubt it. Would you not program other languages because they do not  
have colons? Do you really think the majority of Python users care  
about colons that much? I bet they will never notice if there is any  
colons missing in a piece of Python code if colons are made optional. 



More information about the Python-ideas mailing list