Guido's new method definition idea

News123 news123 at free.fr
Sat Dec 6 13:02:22 EST 2008


Daniel Fetchinson wrote:
> 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

Hmm,


I'd give the proposal a -1. Perhaps I'm missing something though.

Does this really justify an enhancement?
Whether the implicit parameter is prepended with a dot or whether it's
the first parameter with the parantheses doesn't save me any typing and
the benefit of 'visualizing' how the function should be called seems
minor to me.

What would be interesting would be some syntactical sugar to get rid of
the 'self' (at least in the code body).

example:
class C:
    class_elements a,b,c,d

    def method(self,arg):
	global d
	a,b,c = arg[0..3]
	d = a + b
	self.e = a + d

instead of
class C:
    def method(self,arg):
	self.a,self.b,self.c,self.d = arg[0..4]
	self.e = self.a + self.b



As far as I understood (I never really followed any of these threads),
getting rid of self has already been discussed and rejected many times.



bye


N



More information about the Python-list mailing list