[Python-ideas] Making colons optional?

Jared Grubb jared.grubb at gmail.com
Fri Feb 6 18:09:17 CET 2009

> So you do agree colons are line noise? Colons are unpleasant for me  
> not because I have to type them (though this certainly is a factor,  
> too), but I have to *read* them every time I read Python code and  
> they disrupt the mental flow.
> You are assuming colons improve readability, which I disagree.  
> Readability comes from indentation, not from punctuation. If you  
> logic holds, you might have to use semicolons as well.

Just because punctuation is not necessary does not mean it's not  
useful. For example, you could argue that "f(1,2,3)" and "f(1 2 3)"  
should be both allowed. Or you could argue that you dont even need  
colons OR semicolons in one-liners: "if condition do_f() do_g()  
do_h()". At some point aesthetics matters (even if it is an objective  

One major difference between semicolons and colons is their frequency  
of use. A colon once every 8-10 lines of code is less tedious/noisy  
than a semicolon on EVERY line of code. Second, a colon always  
precedes a linebreak AND an indent (a visible change), but semicolons  
never precede anything but a simple linebreak. Colons and indents are  
complementary. Third, colons and semicolons look similar; in some  
ways, colons are more useful when semicolons are NOT used because  
visual ambiguity is lower.

I almost never forget a colon in Python, because (to me) they feel and  
look natural (and the parser gives a great error message when a colon  
is missing!).  I get missing-semicolon and missing-brace errors in C++  
often enough (albeit infrequent) that I do NOT miss them in Python  
(and the cryptic error messages they cause, sometimes in different  
files than the one they're missing from)


More information about the Python-ideas mailing list