[SciPy-dev] Generic polynomials class (was Re: Volunteer for Scipy Project)

Ralf Gommers ralf.gommers at googlemail.com
Thu Oct 15 08:57:36 EDT 2009


On Thu, Oct 15, 2009 at 3:09 AM, Anne Archibald
<peridot.faceted at gmail.com>wrote:

>
> I have to say, though, that an implementation that is hard to
> understand won't be very friendly to maintainers or users of the
> package. And metaclasses and class-producing functions are straying
> dangerously into that territory. Limited though inheritance is, it is
> at least a very standard well-understood way of sharing code in
> python.
>
> This whole discussion is very interesting, and I have looked at both your
code to learn something. Here I would like to give my 2c: Charles solution
is not that difficult to understand. To me it was clear very quickly where
to look in the code, and also clear (in principle) how to implement a new
basis.

You also brought up concerns like being able to use isinstance, and
introspection. As far as I can tell it works as expected. Try running the
following:

############################################################
from polycheb import *

MyCheb = Chebyshev([1, 2, 3])
# check some simple attributes
print 'Roots : ', MyCheb.roots()
print 'Coefs : ', MyCheb.coef

# we can check if our instance is really a Chebyshev class
print 'Is MyCheb instance of Chebyshev? : ', isinstance(MyCheb, Chebyshev)

# in what module is our class defined?
print 'Class defined in module : ', Chebyshev.__module__
# what does it inherit from?
print 'Inherits from : ', Chebyshev.__bases__

# The docstring is a bit uninformative, should link to chebroots
links_to_func = (MyCheb.roots.__doc__.find('chebroots') != -1)
print 'Does docstring link to actual implementation? : ', links_to_func
############################################################

Printed results:

Roots :  Cheb(2)
Coefs :  [ 1.  2.  3.]
Is MyCheb instance of Chebyshev? :  True
Class defined in module :  polyclass
Inherits from :  (<type 'object'>,)
Does docstring link to actual implementation? :  False


Except for the docstring which is easy to fix, it looks nice. There's of
course nothing wrong with inheritance either, but when looking at your
ChebyshevBasis I could already use an inheritance diagram. I do see you have
more bases in there so maybe it's not a fair comparison.

Just my 2c, please keep the insights coming!

Cheers,
Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20091015/50665782/attachment.html>


More information about the SciPy-Dev mailing list