[Python-ideas] Making colons optional?

Scott Dial scott+python-ideas at scottdial.com
Thu Feb 5 18:07:39 CET 2009


Christian Heimes wrote:
>    def method(self, some, very, long, method,
>               going, over, lots,
>               and, lots,
>               and, lots, of, lines):
>        pass
> 

This example line-continues via parentheses, so why isn't the
right-paren enough?

>     if (some() and some_other() or some_more(complex=(True,))
>         and a_final_call(egg=(1,2,3))):
>         do_something()

This example uses the same mechanism as above. BTW, I tend to indent
this as:

    if (some() and some_other() or some_more(complex=(True,))
            and a_final_call(egg=(1,2,3))):
        do_something()

With or without the colon, and it's more readable than your version
(IMHO), and clearly the colon provides no aide to it.

> You see a line starting with "if" but not ending with a colon. You know
> for sure that you have to search for a trailing colon in order to find
> the end of a very long "if" line.

I'd also add that every C programmer has dealt with this before with
single-statement if clauses that require no braces. This is after all
the reason why I indent line-continued test expression the way I do..

> Yes, the colon is extra noise but it's the kind of good noise that makes
> life more joyful like the noise of rain on a roof. Did you notice that
> I'm using a colon in my regular postings, too? I've used two colons to
> separate my text from the examples. Colon separators are natural to me.

All said, I would prefer to keep the colons as well.. I like regularity
of colon<=>suite equilibrium. Even if the splicing operator spits in the
face of it, rarely do you see [x:y] line-continued to leave a naked
colon at the end of the line.

-- 
Scott Dial
scott at scottdial.com
scodial at cs.indiana.edu

-- 
Scott Dial
scott at scottdial.com
scodial at cs.indiana.edu



More information about the Python-ideas mailing list