>
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.