> What if the colon were made optional, with an eye to perhaps eventually no longer using it as the preferred style for new code?

> But if a line beginning as a compound statement and ending without a colon is *never* going to have a valid meaning as something else... what's the point of the colon, otherwise? Seems like just grit on the screen.

That's a very interesting idea, and could perhaps be a viable design decision for making a new language. But, I strongly suspect that the current usage of the colon is far too fundamentally nested in the foundations of Python, and is likely not going to change.

Even if it was simply made optional, it would no doubt introduce quite a lot of confusion and add an extra cost to Python's learning curve, for both newer and older developers. Introductory Python guides all over the place would also have to updated, to mention that in version x, developers may see this code example with or without the colon. In order to justify this, it has to be worth the cost.

You main argument for it seems to be that it's unnecessary, and ends up being an extra character without a real purpose. I don't find this to be worth the cost associated with making it optional.

Also, that assumes that it *is* entirely without purpose. Personally, I find that it helps as a visual queue, to indicate that the next line is within the block of the statement that proceeds the colon. This isn't a huge deal in one line statements, but when it carries over to the next line it greatly helps to distinguish one level from the next.

For example, PEP8 mentions the following code formats as "acceptable options" of handling multi-line statements:


(1)
# No extra indentation.
if (this_is_one_thing and
    that_is_another_thing):
    do_something()

(2)
# Add a comment, which will provide some distinction in editors
# supporting syntax highlighting.
if (this_is_one_thing and
    that_is_another_thing):
    # Since both conditions are true, we can frobnicate.
    do_something()

(3)
# Add some extra indentation on the conditional continuation line.
if (this_is_one_thing
        and that_is_another_thing):
    do_something()


Now, let's take the colon away and see what it looks like:


(1)
# No extra indentation.
if (this_is_one_thing and
    that_is_another_thing)
    do_something()

(2)
# Add a comment, which will provide some distinction in editors
# supporting syntax highlighting.
if (this_is_one_thing and
    that_is_another_thing)
    # Since both conditions are true, we can frobnicate.
    do_something()

(3)
# Add some extra indentation on the conditional continuation line.
if (this_is_one_thing
        and that_is_another_thing)
    do_something()


This might be a bit subjective, but to my eyes this makes the block that's within the statement rather difficult to distinguish; particularly for (1) and (2). The effect would only be amplified in more complex code.

On Thu, Jan 16, 2020 at 1:15 PM Random832 <random832@fastmail.com> wrote:
On Tue, Jan 14, 2020, at 18:15, David Mertz wrote:
> For what it's worth, after 20+ years of using Python, forgetting the
> colon for blocks remains the most common error I make by a fairly wide
> margin. Of course, once I see the error message—even being not all that
> descriptive of the real issue—I immediately know what to fix too.

What if the colon were made optional, with an eye to perhaps eventually no longer using it as the preferred style for new code?

We had a post a while ago about the possibility of using the lack of a colon as an implicit line continuation (like with parentheses, e.g. "if a\nand b:", and this was (reasonably) rejected. But if a line beginning as a compound statement and ending without a colon is *never* going to have a valid meaning as something else... what's the point of the colon, otherwise? Seems like just grit on the screen.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@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/J47TEY2KFGATFMQ7RSZJO7B4RV7KEYWJ/
Code of Conduct: http://python.org/psf/codeofconduct/