Guido's new method definition idea

Patrick Mullen saluk64007 at gmail.com
Sat Dec 6 01:47:50 EST 2008


>> Daniel Fetchinson wrote:
>>> http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-
> stay.html
>>>
>>> The proposal is to allow this:
>>>
>>> class C:
>>>     def self.method( arg ):
>>>         self.value = arg
>>>         return self.value
>>>
>>> instead of this:
>>>
>>> class C:
>>>     def method( self, arg ):
>>>         self.value = arg
>>>         return self.value
>>> I'd like this new way of defining methods, what do you guys think?

I don't really like the proposed syntax any better than the old
syntax.  I certainly wouldn't use "def self." in any of my old code.
I doubt I would use it in a new project were I to have the choice
either.  However, I don't really have a problem with other people
liking it.

the symetry of "def self.func(blah)==def func(self,blah)" and
"ob.func(blah)==func(ob.blah)" is kind of neat.

Could I do something like this:

def a.add(b): return a+b

Outside of a class?  Of course then that makes you think you could do
5.add(6) or something craaaazy like that.  (I mean, you can do
(5).__add__(6) but that's something else entirely)



More information about the Python-list mailing list