[Python-Dev] Re: the "3*x works w/o __rmul__" bug

Alex Martelli aleaxit at yahoo.com
Tue Oct 28 13:49:50 EST 2003

On Tuesday 28 October 2003 07:37 pm, Guido van Rossum wrote:
> > You're making a mountain of a molehill here, Alex.  I know that in
> > group theory there are non-Abelian groups (for which AB != BA), but
> > I've never encountered one myself in programming; more typical such
> > non-commutative operations are modeled as __add__ rather than as
> > __mul__.
> I need to give myself a small slap on the forehead head, because of
> course non-square matrix multiplication is an excellent example where
> AB != BA.  However even there, Ax == xA when x is a singleton, and the
> issue only arises for integers, so I still don't think there are use
> cases.

There may be no "perfectly correct code" that will ever notice 3*x weirdly
works.  But would that make it acceptable to return 42, rather than raise
IndexError, when a list of length exactly 33 is indexed by index 666?  That,
too, might "have no practical use cases" for perfectly correct code.  But
programmers make mistakes, and one of Python's strength is that it does
NOT (crash, hang, or) return weird wrong results when they do -- most
often it raises appropriate exceptions, which make it easy to diagnose and
fix one's mistakes.  Thus, it troubles me that we can't do it here.

I know it's hard to fix (I've stared at that code for QUITE a while...).  But
"deducing" from that difficulty that the error's not worth fixing seems like
a classic case of "sour grapes":-).


More information about the Python-Dev mailing list