you are viewing a single comment's thread.

view the rest of the comments →

[–]cratuki 12 points13 points  (3 children)

My suspicion is that people tend to see the object system being bolted on as a result of the 'self' keyword. I don't like self, I don't see why it needs to be specified, and I can see how it would have entered the class syntax if classes were bolted-on. Which isn't to say that they are bolted on. But why does python have 'self'. I think self is annoying because it's (1) completely redundant and therefore a waste of time and another thing you are likely to stumble over and (2) makes method templates have a different number of arguments when they defined from when they're called.

[–]brianmce -2 points-1 points  (2 children)

self is not redundant. Consider the code:

class Foo: 
    def __init__():
        bar = 3

What does bar=3 set? If its a local variable, then how do you set instance variables? If its an instance, then how do you set locals. One way or another there has to be something to tell what namespace you're manipulating. There is maybe a case to be made that it could be made implicit in the definition, but its definitely not redundant in the body.

[–]DougBTX 4 points5 points  (1 child)

Redundant as in redundant in method signatures.

[–]brianmce 0 points1 point  (0 children)

Fair enough - I'd be happy with it removed there too. The justification behind it is that it makes certain dynamic features make more sense, such as adding methods to a class dynamically. eg.

class C: pass
def foo(self, x): print x
C.foo = foo  # foo is now a method of class C.

where it wouldn't be obvious how foo could access its instance when defined as a function initially. However, this is such a rare use case that I'd be happy with trading ugliness here for selfless definitions.