One last shot at the Augmented Assignment PEP

Alex Martelli aleaxit at yahoo.com
Thu Sep 14 18:08:25 EDT 2000


"Grant Edwards" <ge at nowhere.none> wrote in message
news:Uk8w5.1638$94.341541 at ptah.visi.com...
> In article <8pous80tul at news1.newsguy.com>, Alex Martelli wrote:
>
> >Without the polymorphism over mutable objects wrt immutable
> >ones, += and its ilk would be mere syntactic sugar of no big
> >real interest.  WITH the polymorphism, they become a precious
> >innovation.  Call them "mutation-suggestors with fallback to
> >rebinding if the object is immutable", if you wish, because
> >that is what they are.
>
> This leads into the an new field:
>
>             programming via suggestions and hints

Also known as polymorphism.  You call a method on an object,
it (presumably) does what's appropriate to it.


> I suppose if you really want assignment you can do it
> explicitly with the old syntax.  If you know that you really
> want mutation, you can use the method call to make it explicit.
> That way you get the proper error if you try to mutate an
> immutable object.

Exactly.  And when you want the object to do the appropriate
thing whether it's mutable or not, you use a polymorphic call,
in this case +=.  Much better than explicit typeswitching...


Alex






More information about the Python-list mailing list