[Tutor] class methods as static methods?

Alex Hall mehgcap at gmail.com
Sun May 30 15:56:28 CEST 2010


On 5/30/10, Alan Gauld <alan.gauld at btinternet.com> wrote:
> "Alex Hall" <mehgcap at gmail.com> wrote
>
>> that it will hit. I would like to not instantiate a Harpoon object,
>> just call the Harpoon's getImpactCoords method and pass it the
>> required arguments. Is this possible?
>
> Others have pointed out that
> a) This is possible using staticmetjhod or classmetjod decorators and
> b) it seems a strange choice since you would expect the ability to
> use more than one harpoon and hence be better with an instance...
>
> I will add that if you really want a class method then maybe
> you can do without the class completely and just use a function?
Yes, that is what I ended up doing for testing, but it works well and
I do not think I will be making missile classes, just put each missile
type in its own file in a weapons subfolder, then import "from weapons
import *" to import all weapon files.
>
> The usual reason for class methods is to operate on the
> class as a whole - ie all instances - it is not to provide
> functionality
> without any instances (except in languages without functions,
> like Java, which really use static methods as a kluge to cover
> their limitations!)
>
> And functioons are much easiert to write and manage than
> instanceless classes!
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap


More information about the Tutor mailing list