by xiongchiamiov · 15y ago · 0 comments
Dammit, people - in Python, "That's clever" is an insult. Learn the philosophy of a language and you'll be much happier using it.
Especially when that keyword is not necessary and when it breaks standard programmer expectations (if I declare a method with 3 parameters, I should call it with 3, not 2).
foo.bar(baz, sputz)
^1 ^2 ^3
When you write a class method, it has more information available to it than a similar subroutine; thus, another parameter.GvR brings up the deeper reasons for explicit self at http://neopythonic.blogspot.com/2008/10/why-explicit-self-ha... .
The error messages related to `self` in method definitions caused me some confusion when starting out with python. For instance if you define a method with no arguments, calling it results in "TypeError: your_method() takes no arguments (1 given)".
It lets you define the name of the this parameter in exactly the same way you pass it.
type Bar(p) =
member x.Foo(bar) = printf "%s %d" bar p
let x = new Bar(10)
x.Foo("Foo bar")
Output: Foo bar 10
And yes, the variables bar and p are type inferred from the %s and %d respectively