3 ms·
>> Why, for instance, do class methods rely on annotations? Python do not have annotations. Decorators are not like java annotations. >>Why not take advantage
by Ingaz 16y ago
>> Why, for instance, do class methods rely on annotations?
Python do not have annotations. Decorators are not like java annotations.
>>Why not take advantage of the explicit self?
I think "self" is good. Python lets you bloody patch python objects and classes in runtime and "self" makes it more clear.
Something like:
class MyClass(object): pass
def setX(self,x): self.x = x
MyClass.setX = setX
mc = MyClass()
mc.getX = lambda self: self.x
(INB4: I do not think that bloody patching is good practice)
- regularfry 16y ago> Python do not have annotations. Decorators are not like java annotations. Sorry, yes - wrong word. The point stands, though. For class methods to require the use of a feature as outside the core syntax as decorators just screams of a hacked-in afterthought. > I think "self" is good. I am indifferent to it, but the fact that the space in the syntax opened up by requiring an explicit receiver on all method definitions is not taken advantage of for class methods speaks volumes.
- Ingaz 16y agoClass methods are not so useful in python as in java and C#. I think that classmethods was added only for java/C# folks. In fact it's always better just to combine defs in module and use it as module.method. I like the approach in Scala with "objects" (Scala-singletones). About "self": I don't understand you. Can you show me a language with optional (not forced) OOP, that lets you bloody patch objects and classes that deals with this problem in better way?