On Sat, Aug 19, 2023, 7:27 PM Celelibi <celel...@gmail.com> wrote: > 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. >
>From "Increment (++) and decrement (--) operators should not be used in a method call or mixed with other operators in an expression" https://rules.sonarsource.com/cpp/RSPEC-881/ : *** ### Noncompliant code example u8a = ++u8b + u8c--; foo = bar++ / 4; ### Compliant solution The following sequence is clearer and therefore safer: ++u8b; u8a = u8b + u8c; u8c--; foo = bar / 4; bar++; ## Resources - MISRA C:2004, 12.1 - Limited dependence should be placed on the C operator precedence rules in expressions. - MISRA C:2004, 12.13 - The increment (++) and decrement (--) operators should not be mixed with other operators in an expression. - MISRA C++:2008, 5-2-10 - The increment (++) and decrement (--) operator should not be mixed with other operators in an expression. - MISRA C:2012, 12.1 - The precedence of operators within expressions should be made explicit - MISRA C:2012, 13.3 - A full expression containing an increment (++) or decrement (--) operator should have no other potential side effects other than that cause by the increment or decrement operator - CERT, EXP30-C. - Do not depend on the order of evaluation for side effects - CERT, EXP50-CPP. - Do not depend on the order of evaluation for side effects - CERT, EXP05-J. - Do not follow a write by a subsequent write or read of the same object within an expression *** https://awesome-safety-critical.readthedocs.io/en/latest/ links to e.g. MISRA, CERT
_______________________________________________ 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/BBMJQRQYK4AXGIYZ7BAWEWBUTNOOR37H/ Code of Conduct: http://python.org/psf/codeofconduct/