Too many 'self' in python.That's a big flaw in this language.

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Thu Jun 28 01:00:23 EDT 2007


Jorgen Bodde a écrit :
> I had the same feeling when I started, coming from a C++ background, I
> forgot about self a lot, creating local copies of what should be an
> assign to a class instance, or methods that could not be found because
> I forgot 'self' .
> 
> Now I am 'kinda' used to it, as every language has some draw backs
> (you can't please all). But, what about something in between like only
> using the dot (.) for a shorter notation?
> 
> self.some_var = True
> 
> Could become:
> 
> .some_var = True
> 
> Which basically shows about the same thing, but you leave 'self' out
> of the syntax. Ofcourse it should not be allowed to break a line
> between the dot and the keywords, else Python would never know what to
> do;
> 
> my_class()
> .my_var = True
> 
> Should not be parsed the same as;
> 
> my_class().my_var = True
> 
> Just a suggestion. I am pretty happy with self, but I could settle for
> a shorter version if possible.
> 
What is nice with the required, explicit reference to the instance - 
which BTW and so far is not required to be *named* 'self' - is that it 
avoids the need for distinct rules (and different implementations) for 
functions and methods. The different 'method' types are just very thin 
wrappers around function objects. Which in turn allow to use 'ordinary' 
functions (defined outside a class) as methods - IOW, to dynamically 
extend classes (and instances) with plain functions. Uniformity can also 
have very practical virtues...



More information about the Python-list mailing list