[Python-ideas] Making colons optional?
scott+python-ideas at scottdial.com
Fri Feb 6 08:23:47 CET 2009
Riobard Zhan wrote:
> Your strong association with "here comes a suite" should come from
> indentation, that's how Python works.
Your argument makes no sense, since an indention does not automatically
indicate a suite. We as programmers regularly indent line-continuations
for the sake of code readability, and we rarely break lines after a
colon. This is a certainly a style and not a law, but it's *the* style
of Python, codified by PEP 8:
The preferred way of wrapping long lines is by using Python's implied
line continuation inside parentheses, brackets and braces. If
necessary, you can add an extra pair of parentheses around an
expression, but sometimes using a backslash looks better. *Make sure to
indent the continued line appropriately.* The preferred place to break
around a binary operator is *after* the operator, not before it.
Although the binary operator instruction might lead to breaking "[x:y]"
into "[x:\ny]", many in the community have rejected that as good form.
Perhaps it should be noted in the PEP 8 guidelines that its bad.
Presuming that is accepted practice, one can easily assert that colons
at the end of a line in (well-written) code precede suites. On the other
hand, you have no hope of making such an assertion about indentions.
> Or you should fallback to opening
> and ending braces like Java/C (or even old school begin-end keywords)
> if you fail to do so.
Huh? You want to add more line noise? The colon is a pleasant compromise
between the "please give me some indicator that is visual" and the
"please don't make me type extra characters" crowds. Your arguments that
people who don't want to type them shouldn't don't hold up when you
consider that other people have to read the code, and they are not given
the option to put the colons back in upon reading it. And there is the
simple fact that a piece of code will be read more often than it is ever
wrote. Does your burden out weigh all of the potential readers of your code?
scott at scottdial.com
scodial at cs.indiana.edu
More information about the Python-ideas