Organisation of python classes and their methods

Martin Hewitson martinhewitson at mac.com
Fri Nov 2 18:40:34 CET 2012


On 2, Nov, 2012, at 06:24 PM, Paul Rubin <no.email at nospam.invalid> wrote:

> Martin Hewitson <martinhewitson at mac.com> writes:
>> Well, here we disagree. Suppose I have a class which encapsulates
>> time-series data. Below is a list of the absolute minimum methods one
>> would have to process that data. ... 
>>   'abs'
>>   'acos'
>>   'asin'
>> ...
> 
> Ok, THERE is your problem.  Why do you have separate implementations of
> all those functions?  Does the abs of a time series simply mean the abs
> of each element of the series?  In that case you want just ONE method,
> something like "map", which applies an arbitrary function to all
> elements of the series.  Then for time series ts, instead of saying
> ts.abs(), you'd say ts.map(abs) where abs is the existing, built-in
> absolute value function.  You could similarly say ts.map(acos) etc.
> That gets rid of almost all of those methods.

Well, because one of the features that the framework will have is to capture history steps (in a tree structure) so that each processing step the user does is tracked. So while methods such as abs(), cos(), etc will eventually just call a built-in method, there will be some house-keeping around them. All that said, as I've been trying to implement this structure, it turns out that in Python, this is more naturally achieved (I think) if each algorithm is implemented as a class, so that each algorithm can return its set of supported parameters for validation against the user inputs and, ultimately, for inclusion in a step in the history tree. Since most of that infrastructure will turn out to be boiler-plate code, it would make sense to have an algorithm base class, which all other algorithms (abs, cos, etc) will inherit from. Then I just need to get my head around the interplay between these algorithm classes and the data classes. Some more prototyping needed.

Thanks for the info about map(); this will likely turn out to be very useful, if not at the user level, at least within the framework. Again, a main requirement is that the users should be able to work without knowing much about Python or programming in general; they just get this toolkit and, after minimal training should be able to do most of what they want in an intuitive way.

Cheers,

Martin



> -- 
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list