Unification of Methods and Functions

Neil Benn benn at cenix-bioscience.com
Tue May 25 07:21:05 EDT 2004


David MacQuigg wrote:

>On Tue, 25 May 2004 15:31:49 +1200, Greg Ewing
><greg at cosc.canterbury.ac.nz> wrote:
>
>  
>
>>David MacQuigg wrote:
>>    
>>
>>>My perspective may be different, because I have not yet absorbed the
>>>Python traditions, and I don't have any instictive avoidance of static
>>>methods.
>>>
>>><snip>
>>>      
>>>
>>But Python has modules for use as general-purpose
>>namespaces. Classes are thus relieved of the burden
>>of performing this double duty, leaving them free to
>>concentrate on what they do best, which is defining
>>the behaviour of a collection of objects.
>>    
>>
<snip>

The point is that a static method defined in a class _is_  a part of the 
object model.  There are many, many object models where you would have a 
static method that _belongs_ to the class.

    For a dummy example :

--

A dodo class which has a method to return a new dodo when it is born.

A dodo class with a static method to return the first ever dodo (the 
uber-dodo!), this is a static method - making the constructor return the 
same dodo each time is counter intuitive.

ALSO

A dodo class static method of Dodo.makeExtinct(), this applies to the 
Dodo class (species) and not to the individual dodo (animal).

--

    In addition, when returning a singleton, that should live in with 
the class as the fact that a class in only available as a singleton is a 
factor of the design of the class and should not be linked to another 
namespace.

    I am a ex-Java/.NET programmer so I admit I'm biased but the problem 
is not language specific, it's design specific.  I do understand that in 
Python this is only syntatic sugar but using a module namespace to 
acheive these needs removes what is a link in the design.

Cheers,

Neil

-- 

Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 46
D-01307
Dresden
Germany

Tel : +49 (0)351 4173 154
e-mail : benn at cenix-bioscience.com
Cenix Website : http://www.cenix-bioscience.com





More information about the Python-list mailing list