Py3K idea: why not drop the colon?

Michael Hobbs mike at hobbshouse.org
Fri Nov 10 11:37:08 EST 2006


Ben Finney wrote:
> Please don't hide your new thread as a reply to an existing, unrelated
> message. Start a new message if your message isn't actually a reply.
>
>   
My apologies. My email client was apparently hiding some important 
headers from me.

>> The colon that divides the statement therefore seems redundant. The
>> colon could continue to be used for single-line statements:
>>     if self.hungry: self.eat()
>>     
>
> Why have two different syntaxes for the same statement?
>
>   
Why am I allowed separate statements with semi-colons in addition to 
newlines? Why have triple-quoted long strings in addition to 
single-quoted short strings? Why do I have to type backslash to continue 
a line, except when I'm currently inside parens, brackets, or braces?

The answer is that it's a matter of convenience for the most common 
case, with some exceptions allowed for the exceptional cases.

>> I think the colon could be omitted from every type of compound
>> statement: 'if', 'for', 'def', 'class', whatever. Am I missing
>> anything?
>>     
>
> A use case. What problem is being solved by introducing this
> inconsistency?
>   
The same problem that is solved by not having to type parens around the 
'if' conditional, a la C and its derivatives. That is, it's unnecessary 
typing to no good advantage, IMHO. I was coding in Ruby for several 
months and got very comfortable with just typing the if conditional and 
hitting return, without any extra syntax. When I came back to Python, I 
found that I felt annoyed every time I typed the colon, since it 
obviously isn't required. The FAQ says that the colon increases 
readability, but I'm skeptical. The indentation seems to provide more 
than enough of a visual clue as to where the if conditional ends.

As far as using the FAQ as gospel, the FAQ also provides arguments for 
why there isn't a with statement or a switch statement. The with 
statement has already been implemented in 2.5 and there's a PEP to 
implement switch (3103).

- Mike




More information about the Python-list mailing list