2023-08-04 8:18 UTC+02:00, daniil.arashkev...@gmail.com
<daniil.arashkev...@gmail.com>:
> Currently in Python we have construction like this:
>
> tt = 5
> while t:
>     # do something
>     tt -= 1
>
> It would be great if in Python we have something like this:
> tt = 5
> while (tt--):
>     # do something
>
> It is exists in C++. And in my opinion it is very Pythonic

Just as a reminder of C/C++: {pre,post}-{inc,dec}rementations bring
their lot of issues with the language. Mostly the infamous *undefined
behavors*. If you've done some C or C++ this very expression might
send shivers down your spine.

Assuming a = 0, what's the value of a after: a = a++ ?
What's the value of the expression (a++) + (++a) ?
What values are passed to the function with: f(a, a++, a) ?

I am not sure these would be welcome in python. And allowing such
syntax wouldn't feel really pythonic.

The worst part is not that the evaluation order is not always defined.
It's that even if it were, most people wouldn't remember the rules
since they're not obvious from the syntax. I'm not even sure most C
programmers know what a "sequence point" is.

Some of the backlash about the walrus operator was precisely that it
makes the order of evaluation much more important to know in order to
understand a program.
Assuming a = 0, what does this do: print(a, (a := a + 1), a) ?
At least python makes it defined and obvious *when* the side effect
occurs... As long as you know that expressions are evaluation left to
right.

Best regards,
Celelibi
_______________________________________________
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/VBHRSOPRCM5RMPADJTV4TZWROCDZY263/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to