Another try at Python's selfishness

n.estner at gmx.de n.estner at gmx.de
Fri Feb 3 06:51:03 EST 2006


> First of all, you are using a really poor example of a "method",
> since it doesn't use any attributes of the Foo instance.

Agreed. I tried to post a short example, and it obviously was to short
to make my point clear. lets take a longer one. Current syntax:

class Pair:
    def __init__(self, a,b):
        self.a = a
        self.b = b

    def sum(self):
        return self.a + self.b

    def product (this):
        return this.a + this.b

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

> 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. 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)

> So far, the existence of x.y somewhere
> in Python always implied that x was already introduced explicitly
> in the program,

Yes, but y(x) also implies that x and y have been introduced explicitly
before, unless it's in a "def" statement. The def statement always
introduces new variables.

> and you suggest that we violate that both in the
> "def self.x"-row, and inside the methods when we access attributes.

  def x(self):
declares two new identifiers, "x" and "self"

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

Attribute acces wouldn't change.




More information about the Python-list mailing list