[Python-ideas] Revise using the colon ( : )

2023-09-06 Thread Stephen J. Turnbull
Morteza Mirzakhan writes:

 > In my opinion, using a colon after keywords such as `if`, `elif`,
 > `else`, `for`, `while`, `try`, `except`, and `finally` is quite
 > unnecessary.

Sure, but that would be a different language.  I like the formality of
the colon, and it helps in visually parsing the test in cases where
the test expression covers more than one line and contains
parentheses.  I think you're very unlikely to get any uptake from the
core developers on this, not because I don't like it but because it's
a change for no reason except one person doesn't like colons.

But it should be an easy experiment to try.  Change the grammar so
that colons are optional in those places.  Then try to build Python
and see what happens.  I think that has a good chance of working.  (It
definitely won't work if you omit the colons entirely: all of the
Python code in the stdlib will stop working!)

If it does, then you can try your "Pytho" language (missing one
character at the end, you see?) and see how you like it and if you can
get uptake from others.  If you do, then you can prohibit colons in
those places and start the tedious work of making the stdlib work
without them.  I still doubt you'll get a large following from
Pythonistas but who knows? :-)



___
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/AWD6QBGRG4GU6OZ2ENJTWEG3E3S3ZDZE/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Revise using the colon ( : )

2023-09-05 Thread Morteza Mirzakhan
Dear Python Developers,

I would like to share my thoughts on the use of the colon mark “:” in
Python code.

In my opinion, using a colon after keywords such as `if`, `elif`, `else`,
`for`, `while`, `try`, `except`, and `finally` is quite unnecessary.

Using mandatory indentation in Python to group commands into a block is
similar to how curly braces `{}` are used in ‘curly-bracket languages’ like
C-family, Perl, Java, PHP, etc. to group multiple commands into a single
statement.

While those compilers don't differentiate between one or more ‘space’ or
‘return’ characters, so they don't recognize new lines and indents, the
indentation is also used, not forced but traditionally, to increase
readability. However, when it comes to writing just one instruction after
the head command, you can omit the curly braces `{}` and simply write it in
a new line, traditionally indented in C-family languages.

So Python is one step forward by not requiring curly braces `{}` whether
the block includes one or more lines.

In contrast, the requirement to use a colon after those keywords in Python
is a drawback!

The colon “:” doesn't improve readability but adds unnecessary complexity,
increases the potential for errors, and requires more effort to code. This
is because the requirement does not have a logical meaning while the block
is made obvious by indentation, so coders may forget to include the colon
and face errors.

This can be particularly frustrating for those who are used to coding in
languages such as C and C++, where blocks of code are traditionally
indented and no curly braces `{}` are used when the following tail is a
singe-command instruction.

The suggestion is removing the need by interpreter for the use of colon
after keyword syntaxes (and making it optional due to Backward
Compatibility) in the new revision of Python.

I believe this change would make Python code easier to read, less prone to
errors, and require less effort to code.

Thank you for your time and attention.

Best regards,
Morteza Mirzakhan
___
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/E7LCNY6LBWQ5HHI6BHWRDXFE2MMIBZCC/
Code of Conduct: http://python.org/psf/codeofconduct/