2 ms·
I also like how you can call the method on the class and pass self in explicitly. e.g.: class Foo: b = 4 def foo(self, a): return a + s
by fiddlerwoaroof 8y ago
I also like how you can call the method on the class and pass self in explicitly. e.g.:
class Foo:
b = 4
def foo(self, a):
return a + self.b
inst = Foo()
inst.foo(3)
Foo.foo(inst, 3)
I haven't written python in a while, but I really like that python makes this possible and obvious and I've found this behavior pretty handy when working in a more functional style.
- fiddlerwoaroof 8y agoAlso, I find writing languages with an implicit self like Java, Kotlin and Scala really irritating because there's nothing to distinguish access to a locally-scoped variable or function from access to a class member. I've always appreciated how, in Python, `x` always refers to something bound according to Python's pseudo-lexical scoping rules while class members always have a `self.` to make them stand out. These days, however, I mostly write Common Lisp and Clojure which, each in their own way, have explicit selfs: Common Lisp because it uses multiple dispatch and, consequently, there isn't one "self" and Clojure's protocols are designed to dispatch on the first argument, which is always passed explicitly.