Augmented Assignement (was: Re: PEP scepticism)
uioziaremwpl at spammotel.com
Fri Jun 29 15:42:06 EDT 2001
On Fri, 29 Jun 2001, Roman Suzi wrote:
> On 29 Jun 2001, Bernhard Herzog wrote:
> >"Alex Martelli" <aleaxit at yahoo.com> writes:
> >> "Bernhard Herzog" <bh at intevation.de> wrote in message
> >> news:6qn16r7i69.fsf at abnoba.intevation.de...
> >> > I think the main problem (in as much as there actually is a problem) is
> >> > that whether augmented assignment rebinds the left hand side depends on
> >> > the type of object, i.e. whether the object implements the appropriate
> >> Right! I think the main advantage (in as much as there actually is an
> >> advantage) is that whether augmented assignment rebids the left hand
> >> side depends on the type of object. i.e. whether the object implements
> >> the appropriate methods. This is called *polymorphism* and is a concept
> >> of *HUGE* power.
> >Well, polymorphism is certainly very important and powerful in python
> >but in an of itself that's no argument in favor of the intricacies of
> >augmented assignment in Python. Just because something could depend on
> >the types of the objects involved doesn't mean that it should.
> In fact, many things depend on the type of the objects. Types of the
> objects define what operation will be done. For example, in a simple
> A = A + 1
> + operation is different for different A type. It is inevitable that not
> everything is written every time. Everything could not be explicit
> in any place.
The problem which some people have with augmented assignment is not that
they exist, but that they do not work as they expect (at least from the
POV of some readers). I expect that
ident op= expr
ident = ident op expr
At least that's what I'd have expectd comming from other programming
> >Augmented assignment doesn't actually offer anything that couldn't have
> >been done with explicit method calls,
> They do. Some operations are better defined in terms of "+=".
> For example, list.append()
I think you mean list.extend(). ;)
More information about the Python-list