[PEP 203] Augmented Assignment: Names Needed!

David Goodger dgoodger at bigfoot.com
Mon Aug 14 23:46:21 EDT 2000


I think this feature is a *good thing*, and very Pythonic. That being said,
I think the proposed hook names need rethinking. It's time to "pick
something better"[1] and I hope it's not too late. And I agree with the PEP
that "a firm decision by the BDFL"[2] *is* needed.

IMHO the proposed __add_ab__ is awkward, needs explanation, and hard to type
(not *another* underscore, please!). The various 'in-place' versions are
misleading, I find, because for immutable objects 'a += 1' is *not* in-place
at all, just a shortcut for 'a = a + 1'. The rebinding of the name to a new
object is still there. How about renaming the internals as well for
consistency, changing (for example) bytecode INPLACE_ADD to AUG_ADD, or
PyNumber_InPlaceAdd to PyNumber_AugmentedAdd?

Can the Python community come up with a better set of names? Let's try!

I thought of appending 'by' to the hook names, as in '__divby__'. This works
for * (__mulby__) and many others, but is awkward for + (__addby__) and -
(__subby__). Augmented addition could be called '__incrby__' for increase,
but then we're back to implying in-place.

How about using the 'augmented'? __augadd__ or __aadd__? No? Perhaps the
underscore *is* needed :(, so we get __aug_add__ or __a_add__.

__addback__, __mulback__, etc? Nice ring to them! ('Back', as in 'add then
assign back'.) (This one gets my vote, so far.)

These operators appear (syntactically) to transform binary operators to
unary, so how about '__uniadd__'?

I've seen '__addeq__' and its ilk mentioned before; I suppose this would be
acceptable, if nothing else could be found. Easier to relate to the syntax
than '__add_ab__', and superior, IM(NS)HO.

Here's hoping that we can come up with something!

[1] Excerpted from Guido van Rossum's message, where he proposed the 'and
becomes (ab)' form.
http://www.python.org/pipermail/python-list/2000-June/059556.html

[2] http://python.sourceforge.net/peps/pep-0203.html

-- 
David Goodger    dgoodger at bigfoot.com    Open-source projects:
 - The Go Tools Project: http://gotools.sourceforge.net
 (more to come!)




More information about the Python-list mailing list