Augmented Assignement (was: Re: PEP scepticism)
Carsten Geckeler
uioziaremwpl at spammotel.com
Mon Jul 2 16:22:19 EDT 2001
On Mon, 2 Jul 2001, Paul Prescod wrote:
> Tim Hochberg wrote:
> >
> > ...
> >
> > Someone made a decision at some point that the builtin mutable types should
> > mutated by augmented assigment. If the newbies were sacrificed on somebody's
> > alter, it was not NumPy's.
>
> I've come to the same conclusion myself. I don't know what the rationale
> is for this "mutable types behave one way" and "immutable types behave
> another" philosophy.
Well, the Python world before augmented assignment was quite simple:
Operators never changed the objects they acted on. You would never expect
x+y changing the object bound to x or y themselves (except some
brain-twistings user objects with dumb operator overloading). You'd just
expect to return a "sum" (for the object type) of two object.
Now we have augmented assignments. x=+y _can_ change the object bound to
x, depending if x is mutable or immutable. From my POV using a method
call for changing an object in place is appropriate and more readable
(l.extend was perfect for me).
> "Advanced" types could have "smart" behaviour and simple types could
> have x=x+y behaviour.
Cheers, Carsten
--
Carsten Geckeler
More information about the Python-list
mailing list