On Fri, Aug 23, 2013 at 8:36 PM, Graydon Hoare <gray...@mozilla.com> wrote:
> On 13-08-23 11:28 AM, Masklinn wrote:
>
>> For the record, I think augmented assignments are a terrible ideas and one 
>> of the worst features of python.
>
> Could you say more (perhaps more constructively)? I believe we have
> every intention to support these sorts of overloads longer-term; we
> removed the previous support only because it wasn't done terribly well.

Another Python guy here, I feel similar though I wouldn't word it as strongly.
The problem with += *overloads* is that its sole motivation, a += b
not being simple syntactic sugar for  a = a + b, is also very
confusing.
At least that's the problem in the context of Python. I don't know
enough Rust to decide off-hand whether these points also apply to
Rust, so I'll use Python examples:

Suppose a is a list, b is another list, and c is any non-list iterable
(e.g. a tuple which is basically an immutable list).
One inconsistency is that a + c throws an exception but a += c works
just fine (both work with b in place of c).
Another, more tricky, difference is due to Python's data model where
everything is a reference type and aliasable.
Generally, a = a + b constructs a new and the list a referred to
before isn't affected. In contrast, a += b mutates the list a refers
to.
This is important if the list aliased - e.g., passed a parameter,
stored as a field of an object, or something similar.
At least the latter of these two inconsistencies applies to several
other collection types as well (standard library and third party).

Now, of course this behaviour is intentional and quite useful - it's
the sole reason there is a += overload in the first place (instead of
not defining __iadd__, which means a += b really is equivalent to a =
a + b).
But it's also quite unexpected for most people, and although I've
never been bitten by it personally (I'm try hard not to alias mutable
data), it's not hard to see this causing tricky bugs.
But then again, the only reason it can be observed at all is aliasing
of mutable data. I'm not sure how likely that is in Rust.
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to