[Python-ideas] Technical possibilities for a syntax [was: Reverse assignment operators ...]

Paul Moore p.f.moore at gmail.com
Wed Nov 16 14:36:04 EST 2016


On 16 November 2016 at 17:50, Ryan Gonzalez <rymg19 at gmail.com> wrote:
> If someone decided to be weird and have __add__ and __iadd__ do two
> different things, this would completely break that. Granted, that's a stupid
> idea to begin with, but it's still poor justification for the code breakage.

If you think of a = a + 1 as "assigning the value of the expression a
+ 1 to a" and a += 1 as "incrementing a by 1" it's neither weird nor
stupid. There are some well-known invariants (for example, that the
value of a after the operation should be one more than the value
before) that would be confusing to violate, but there are plenty of
other aspects of the behaviour that are not so fundamental, and which
can safely and sensibly differ between the two operations.

Paul

PS Note for anyone who wants to take this off on a wild tangent - my
above comment is *in the context of Python as it has been defined for
20+ years*. If you want to write a new language, you can make your own
judgement about any or all of this, and the success of your language
will be the measure of how reasonable your ideas are...


More information about the Python-ideas mailing list