Unification of Methods and Functions

David MacQuigg dmq at gain.com
Thu May 27 13:46:19 EDT 2004


On Wed, 26 May 2004 13:59:33 +1200, Greg Ewing
<greg at cosc.canterbury.ac.nz> wrote:

>Neil Benn wrote:
>>    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.
>
>I don't see it that way. To me, using a module namespace is
>an alternative way of expressing the same link. A naming
>convention for functions (make_dodo, first_dodo,
>extinctify_dodos) would be a third way of expressing the
>link.

To summarize our discussion on static methods, we have four ways to
accomplish the purpose of making a method callable without an
instance.

1) Add the staticmethod wrapper.
2) Create a dummy instance, and use it to call the method.
3) Move the method outside of the class, and if that disturbs the
modular structure of the program, make the class and its external
function a new module with its own namespace.
4) Move the method outside of the class, but make sure it is still
"associated" with the class by giving it a special name.

Is there any reason we *should not* use solution #1?

-- Dave




More information about the Python-list mailing list