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

Charles R Harris charlesr.harris@gmail....
Wed Oct 14 11:21:33 CDT 2009


On Tue, Oct 13, 2009 at 11:03 PM, Anne Archibald
<peridot.faceted@gmail.com>wrote:

> 2009/10/13 Charles R Harris <charlesr.harris@gmail.com>:
> >
> > On Tue, Oct 13, 2009 at 7:24 PM, Anne Archibald <
> peridot.faceted@gmail.com>
> > wrote:
> >> specifying the interval. And if people do want to specify the
> >> interval, using a basis object makes it much easier to avoid
> >> forgetting it and getting nonsensical results (or worse, sensible
> >> results until you try a different interval).
> >>
> >
> > That is because they are low level building blocks, they should have the
> > absolute minimum of crud stuck on, and that means the interval is [-1,
> 1].
> > If you need more, that is what a class is for. That how low level things
> > should work, small functions doing the minimum amount provide the most
> > flexibility. The programmer should be handed enough rope to hang
> themselves
> > at that level if they so choose. That's why folks use C and not Pascal.
>
> Well, the glib answer would be that we're using python, so we should
> choose a pythonic way of doing things. But clearly having the
> low-level functions is important to some potential users - you and
> Robert Kern, plus surely more other people - so where possible the
> code should accommodate the as-low-level-as-possible approach.
>
> How's this for a compromise? The high-level class interface has a
> Polynomial object and various Basis subclasses. For representations
> where having a featureful Basis object is important, the
> implementation should just write one, inheriting as appropriate. For
> representations that don't need this extra stuff, people can just
> write a collection of functions acting on coefficient arrays (as you
> did for the Chebyshev polynomials) and create a basis object using
>
>
I'm trying to get you to consider not using inheritance at all and see how
things look. We might not want to go that way in the end, but inheritance
tends to be overused. Probably because it is the first tool that comes to
mind and because it looks like a cheap way to reuse code. But it is often
not the best tool so folks need to step back and see if there aren't better
ways to get things done. The fact that you are putting some functionality in
the base class indicates that you are thinking along the lines of
implementation. Passing a Basis object into a constructor also doesn't smell
right. The question to ask  is what role you want the Basis object to play
and if it doesn't more naturally belong somewhere else if you weren't
constrained by inheritance. In a sense it looks like you would like to
derive the interface class from the basis object, but somehow that doesn't
seem to work well with inheritance because then it is hard for the derived
objects to share code.

ChebyshevBasis = generate_basis("ChebyshevBasis", mul=chebmul, ...)
>
>
Heh! Well it's does look like a compromise, or rather, design by committee
;) But it is something to think about.


> I have a demonstration implementation in git now.
>
>
OK.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-dev/attachments/20091014/6010a68f/attachment.html 


More information about the Scipy-dev mailing list