[Python-ideas] Making colons optional?

Lie Ryan lie.1296 at gmail.com
Tue Feb 10 05:19:41 CET 2009


On Sun, 08 Feb 2009 03:17:33 -0330, Riobard Zhan wrote:
> 
> The original context is that you thought it's not worth a "big/major"
> change to make colons optional because we get nothing, then I asked by
> comparison what do we get by making "print" a function (a "bigger"
> change for me) when we really have the option to just add a new built-
> in function with a slightly different name.

No, it is not an option because 1) it is duplication of feature 2) having 
two different print construct that have subtle differences confuses the 
hell out of newbies 3) people won't use that new built-in function 4) if 
people don't use the new built-in function, overriding print would 
involve some dark magic 5) to override print statement you need to mess 
with sys.stdout, which is messy as you need to keep a reference to the 
original sys.stdout or face infinite recursion.

The case for colon is different from the case of semicolon. Statements 
between semicolons have sibling relationship, while the statement before 
a colon and the statements after the colon have parent-child relationship.

Sibling relationship is not significant enough to require anything more 
than a newline or -- in the case of several statements in one line -- a 
semicolon. Parent-Child relationship is much more important and having 
colon before the child statements makes it visually easy to distinguish 
the parent and children.

The case for you requesting optional colon is like asking for code like 
this to be legal:

def foo(bar):
    print 'foo'
        print 'bar'
      spit()
            antigravity(bar)
print 'koo'

which would be interpreted as

def foo(bar):
    print 'foo'
    print 'bar'
    spit()
    antigravity(bar)
print 'koo'

and saying: "consistent indentation is unnecessary as computer can 
syntactically distinguish them as long as the number spaces is equal or 
more than the first indentation of the suite"

yeah, although computers can distinguish them easily, human can't.




More information about the Python-ideas mailing list