[Python-ideas] Making colons optional? Syntactic alternative.
leif.walsh at gmail.com
Thu Feb 5 23:06:59 CET 2009
2009/2/5 spir <denis.spir at free.fr>:
> Le Wed, 4 Feb 2009 23:35:30 -0330,
> Riobard Zhan <yaogzhan at gmail.com> a écrit :
>> Hi everybody,
>> I'm proposing to make colons optional.
-1. I like the colons. They're not strictly necessary, but defining
>>> def foo(x)
... return x+1
just looks sloppy to me. The colon helps show it's a definition.
Perhaps this is my anglocentrism (sp?) showing, as in "Here is my
function: ...". Native English speakers will notice how helpful that
> Starting from this point, and looking for clarity and consistency, my wished syntactic revolution ;-) reads as follows:
> * Get rid of ':' at end of headlines.
> * Allow only single-instruction blocks (suites) for one-liners: "if cond; do_that". Or maybe no separator at all is necessary here for unambiguous parsing? Or replace ':' or ';' by 'then'. This would also allow if...then...else one-liners. Alternatively, make newline+indent compulsery. This is anyway often recommended in style guidelines.
I sort of like this. One-liners should be doable with "if cond then
stmt else stmt" instead of "if cond: stmt". I just think it's
prettier; I can't really prove this or try to convince many people.
Another option would be to add "if cond then stmt else stmt", and also
require a newline after a colon, though this would mentally separate
the two forms of 'if'.
> * Extend name binding format "name:value" to assignments. That is, write "a:1" instead of "a=1. This may avoid tons of misunderstandings (imo, '=' for assignment is a semantic plague, a major error/fault, a pedagogic calamity).
Eww. I'll always keep ':=' and '<-' close to my heart, but I can't
envision ':' as assignment.
> * Which lets the "=" sign free for better use: use "=" for the semantics of equality, like in math and common interpretation learnt from school.
Yeah, yeah, yeah...the day we finally get rid of the throngs of
programmers complaining that assignment is too many characters for
their weak little fingers to type will also be the day we finally get
'import soul' working correctly, and never have to program again. If
> * Perhaps: use "==" for identity, instead of "is".
I've always been a fan of 'is'. I think it looks nice.
More information about the Python-ideas