Py3K idea: why not drop the colon?

Doug aj108778 at gmail.com
Sun Nov 12 02:18:48 EST 2006


Michael Hobbs wrote:
> Can anyone find a flaw with this change in syntax?
>
> Instead of dividing a compound statement with a colon, why not divide it
> on a newline? For example, the colon could be dropped from this statement:
>     if self.hungry:
>         self.eat()
> to
>     if self.hungry
>         self.eat()
>
> Python is already sensitive to whitespace and the newline anyway, so why
> not put it to good use? For example, Python rejects this statement
> because of the newline present:
>     if self.hungry or
>       self.depressed:
>         self.eat()
> You need to use the backslash to continue the expression on the next line:
>     if self.hungry or \
>       self.depressed:
>         self.eat()
> 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()
>
> I think the colon could be omitted from every type of compound
> statement: 'if', 'for', 'def', 'class', whatever. Am I missing anything?
>
> Thanks,
> - Mike

It is a very good idea as the colon is technically redundant (not
necessary for parsing, aside from one liners) and actually hurts
readability (and writeability).  The "evidence" people cite for the
advantage of using a colon is research done by users of the ABC
language, python's predecessor.  They forget that A) that was like 20
years ago, B) the language was designed for children, and C) the
keywords in ABC are IN ALL CAPS LIKE THIS (hurting readability and
writeability) and thus adding a colon obviously helps restore some
readability for users in that case but not in python's.

However, python is far too old to accept any fundamental changes to
syntax at this point.




More information about the Python-list mailing list