[Python-ideas] Making colons optional?

Georg Brandl g.brandl at gmx.net
Fri Feb 6 19:46:22 CET 2009


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.

>>
>>> - 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.

By making colon syntax flexible, we also lose a consistent look and feel
of the language.  [1]

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.

>>> - 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 ...

That's your prerogative.  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.

cheers,
Georg


[1] Yes, I have read all those remarks about semicolons.
    What you all fail to recognize is that the majority of Python users
    like the colons, and wouldn't program without them.  You can call
    it habit if you can't understand that it fits their thinking process,
    that's all the same: the colon won't just go away, just because it's
    made optional.  Therefore, consistency is lost, not gained.

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.




More information about the Python-ideas mailing list