3 ms·
See, I hate the use of self, or this in code. We want to specify things exactly in code, and deliberately adding that sort of indirection seems halfway mad. If
by OtterCoder 8y ago
See, I hate the use of self, or this in code. We want to specify things exactly in code, and deliberately adding that sort of indirection seems halfway mad. If forced to write classes, I would much rather refer to the class name from within methods, or something similar.
- imauld 8y agoThis is valid Python: >>> class Foo: ... def __init__(Foo, x): ... Foo.x = x ... >>> foo = Foo(5) >>> foo.x 5 The variable name `self` is a convention as is `cls`. You can name the first argument to a method whatever you please. The same is true for method receivers in Go: type Foo struct { X int } func (Foo Foo) Bar() int { return Foo.X * 2 } That will compile and perform as expected. Not sure about Java/C# but in Javascript you can bind `this` to another variable if you'd like: var Foo = { x: 5, foo: function() { Foo = this return Foo.x * 2; } }