Re: Unification of Methods and Functions

From: Greg Ewing (greg_at_cosc.canterbury.ac.nz)
Date: 05/07/04


Date: Fri, 07 May 2004 15:59:20 +1200

David MacQuigg wrote:
> Static methods
> are necessary because it is a very natural thing to write a method in
> a class that needs to work without being bound to any particular
> instance.

I beg to differ. It might seem natural to someone who's
been exposed to C++ or Java, but I don't think it's
a priori a natural thing at all.

In Python, a function defined inside a class is a method.
If you want a function to be a method, you put it inside
a class. If you don't want it to be a method, you don't
put it inside a class. It's as simple as that.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg


Relevant Pages

  • Re: Unification of Methods and Functions
    ... David MacQuigg wrote: ... > The need for static methods ... > will arise when the student first writes a method that needs to work ... University of Canterbury, ...
    (comp.lang.python)
  • Re: Unification of Methods and Functions
    ... >would have the greatest concentration of unbound method use (my reasoning was ... staticmethod syntax is relatively new, and there is a long tradition ... in Python of using various alternatives to static methods. ...
    (comp.lang.python)
  • Re: Unification of Methods and Functions
    ... > half of what is now in Learning Python, ... There are static methods in Python? ... > appropriate classes is not good programming. ... I must note that Animals_2 is a total abuse of OOP techniques. ...
    (comp.lang.python)
  • Re: Trying to come to grips with static methods
    ... | I've been doing a lot of reading about static methods in Python, ... and possibly getting over-confused by the minutia of the CPython ... as a method (where 'methods', in Python, get semi-magic first parameters). ...
    (comp.lang.python)
  • Re: Unification of Methods and Functions
    ... >> Nobody seems to understand that lambda functions, static methods, etc. ... Python traditions, and I don't have any instictive avoidance of static ... Python programs to the new syntax. ...
    (comp.lang.python)