Some thougts on cartesian products

Christoph Zwerschke cito at online.de
Sun Jan 22 13:12:49 EST 2006


Steven D'Aprano wrote:
> On Sun, 22 Jan 2006 18:29:45 +0100, Christoph Zwerschke wrote:
>> For doing such things I would use a vector subtype of list.
> 
> Not everything needs to be a separate class! Why create a magic class for
> every piece of functionality you want? Just create functions that operate
> on existing classes!
 >
 > What advantage is there to creating a "list with cartesian product"
 > subclass of list?

Principally, you're right (see also my example with iterators).

But I can still see two reasons for classes:

1) That function would have to make a lot of case distinctions (check 
the types of operands). If you have a class, you already know the type 
of the operands (at least one).

2) It allows you to write a*b instead of mul(a,b) which looks nicer.

-- Christoph



More information about the Python-list mailing list