Unification of Methods and Functions

David MacQuigg dmq at gain.com
Tue May 25 06:26:40 EDT 2004


On 25 May 2004 09:46:46 GMT, Antoon Pardon <apardon at forel.vub.ac.be>
wrote:
>Op 2004-05-24, David MacQuigg schreef <dmq at gain.com>:
>> On Mon, 24 May 2004 14:39:11 +1200, Greg Ewing
>><greg at cosc.canterbury.ac.nz> wrote:

>>>We don't see static methods as clutter, because for the
>>>most part we don't see them (i.e. we don't normally use
>>>them). It would be no great loss if they were dropped,
>>>too.
>>
>> I would see it as a loss.  The next best alternative is to move the
>> static method outside of the class, and that puts an arbitrary
>> restriction on how I can structure my programs.  If the person writing
>> the program feels that the function belongs in the class, let's not
>> say it can't be done because either a) The syntax doesn't allow it. or
>> b) We assume he is wrong in thinking his function belongs inside his
>> class.
>>
>> 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.
>
>I never felt the need for static methods, and I still don't think
>of my self as having absorbed the python traditions. Maybe the
>questions is, where do you get your instinct from to use static
>methods?

When I write methods in a class, some of them have instance variables,
and some do not.  Some have global variables.  Some have both globals
and instance variables.  The methods without instance variables are
"static methods".  I have no instinct acquired from Java or some other
language.  I just write whatever method is needed for the task at
hand.  Saying I should avoid static methods seems to me like an
arbitrary restriction.

Class methods are a little different.  I've never felt the need for
one, although I just received a contribution from one of the readers
of this thread - a program using class methods to solve the inventory
problem in Animals_2.  It seems to me that class methods provide
syntax sugar for a very special need, while static methods provide a
way to implement *any* method that doesn't require an instance
variable.  I may be not fully understanding the need for class
methods.

-- Dave




More information about the Python-list mailing list