Another try at Python's selfishness

Steven D'Aprano steve at REMOVETHIScyber.com.au
Fri Feb 3 07:32:47 EST 2006


On Fri, 03 Feb 2006 03:51:03 -0800, n.estner wrote:

> My alternative syntax suggestion would be this one:
> 
> class Pair:
>     def self.__init__(a,b):
>         self.a = a
>         self.b = b
> 
>     def self.sum():
>         return self.a + self.b
> 
>     def this.product ():
>         return this.a + this.b

This would be a fairly major change to Python, so I think we can say right
up front that the chances of this happening before Python 3 are zero, and
even in Python 3 the chances are about the same as the chances of Richard
Stallman suddenly announcing that he's taken a job for Microsoft writing
Digital Restrictions Management software.

But still, let's continue. After all, all you have to do is convince Guido
that this syntax is better...


>> You are really giving "self" a magic meaning with your suggestion
>> which isn't needed at all.
> 
> No. I hope this is clearer in the example above. "self" shouldn't be a
> keyword. 

Which it isn't now either.


> It's a special kind of argument now, so why shouldn't we
> explicitly _declare_ that it's a special kind of argument? (as explicit
> is better than implicit)

And a foolish consistency is the hobgoblin of little minds *wink*

[snip]

>   def x(self):
> declares two new identifiers, "x" and "self"
> 
> Why shouldn't
>   def self.x():
> declare two new identifiers ("x" and "self"), too?

Sure, but now the call foo.bar has special meaning inside a def statement
than elsewhere. Elsewhere, foo.bar is an attribute access, looking up
attribute bar in foo's namespace. Using your syntax, in a def statement
foo.bar is a pair of declarations: it declares a name "foo", and it
declares a second name "bar".

This inconsistency is, I think, worse than the implicit use of self.


-- 
Steven.




More information about the Python-list mailing list