sequence multiplied by -1

Antoon Pardon Antoon.Pardon at
Mon Oct 4 12:48:05 CEST 2010

On Fri, Oct 01, 2010 at 09:44:34AM -0700, Emile van Sebille wrote:
> On 10/1/2010 5:56 AM Antoon Pardon said...
> >Someone provides you with a library of functions that act on sequences.
> >They rely on the fact that '+' concatenates.
> >
> >Someone else provides you with a library of functions that act on
> >numbers. They rely on the fact that '+' provides addition.
> >
> But you can do that now -- you just can't have a class that provides
> _both_ behaviors.

The point was the next two lines, you missed it.

The point is that if for some reason you need number like sequences
or sequence like numbers, one of those libraries will be useless to

Suppose you write your class so that '+' will provide addition and
you provide a method concat to concatenate. Now no matter how usefull
the sequence library would be for you, you can't use it. You will
have to rewrite those function you need, in terms of a concat method
instead of '+'.

That also means that whatever sequence like functions you write
for this class, you can't use those functions for sequences in
general because in general, sequence don't have a concat method.

So the use of '+' for addition as well as concatenation, causes
problems for proper abstraction and writing generic code. That
is why IMO that was an unfortunate choice.

Antoon Pardon

More information about the Python-list mailing list