On Sat, 18 Jan 2020 at 02:32, Josh Rosenberg
<shadowranger+pythonid...@gmail.com> wrote:
>
> The colon remains syntactically necessary in some cases, particularly to 
> disambiguate cases involving one-lining (no block involved). Stupid example: 
> If the colon is optional, what does:
>
> if d +d
>
> mean? Is it a test of the value of d, followed by invoking the unary plus 
> operator as a one-liner (that is, was it "if d: +d")? Or is it testing d + d, 
> and opening a block on the next line ("if d + d:")?

Or, to turn this around,

    if a + b > 0

What is the correct indentation for the following line?

    if a + b > 0:

should be indented

    if a: + b > 0

should *not* be indented. That sort of context-dependent
interpretation is very hard to parse, both for the computer and for
the user. Even if it's technically possible to parse for the compiler,
I'd not want to have to worry when reading a line of code which is
quoted out of context (in a traceback from a bug report, for example)
that I needed to know what the surrounding lines were just to
interpret the meaning.

Yes, this would be a very rare thing to happen, but the lack of such
weird edge cases is key to why Python feels natural and easy to read
for me.

Paul
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/6M5S6QLRYCYI46JFCXFO7SY63CIT5ICB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to