Why self?

Charles Hixson charleshixsn at earthlink.net
Tue Jul 9 14:08:38 EDT 2002


Robb Shecter wrote:
> Brian Quinlan wrote:
> ...
>>
>> Two of those characters are your own fault (the underscores).
> 
> 
> I don't think so:  As I understand it, the double underscores are 
> necessary in order to for the class to function correctly if subclassed. 
> ...
> Robb
> 
If you were arguing in favor of a smarter scoping rule, that would be 
reasonable.  But as an argument against the explicit use of self as the 
first parameter of a method..., probably not.  The errors that this 
causes are quickly caught and corrected.

Question:  is
class TestA:
    def  methodb():
      ...
legitimately accessed as TestA.methodb()?

If so, then the question about the self argument is resolved.  It's the 
marker that distinguises instance methods from class methods.  It is 
legitimate to claim that there ought to be a better way to do this, but 
any language that implemented this would be very divergent from Python. 
  Still, it would be easy to write a pre-processor to turn it into 
Python, as you aren't really tinkering with the basic syntax.  I've 
sometimes thought of doing this to create a dialect that had explicit 
loop markers  (indentation would still be required, but the loop markers 
could be used to reconstitute it if the alignments became corrupted). 
The problem is that dict's use my preferred marker, and tuples and lists 
use the other reasonable choices, and ...  every time I've almost 
decided to do this I've given it up as a bad idea.\


-- 
-- Charles Hixson
Gnu software that is free,
The best is yet to be.




More information about the Python-list mailing list