5 ms·
So indeed the auth of the article is really too clever on this.
by itsnotvalid 16y ago
So indeed the auth of the article is really too clever on this.
- xiongchiamiov 16y agoAnd as usual, being clever in Python equates to getting yourself in trouble. Dammit, people - in Python, "That's clever" is an insult. Learn the philosophy of a language and you'll be much happier using it.
- code_duck 16y agoThat's exactly why I prefer Python over Ruby: not the language, but the philosophy of the community. The Ruby community seems to adore 'clever', while the Python community explicitly shuns it. I view the latter as being more mature and borne of experience.
- chc 16y agoPython itself is pretty "clever" compared to many other languages (GC, lack of obvious 1:1 correspondance between code written and code executed, dynamic typing, significant indentation, decorators, generators, etc.). If Python programmers were really opposed to cleverness, they'd be writing in straightforward assembly or a very thin veneer over it.
- jbri 16y agoPython is "clever" so that the Python programmer doesn't have to be.
- eru 16y agoActually Python has pretty close correspondence between source code and compiled byte code.
- billmcneale 16y agoA language that forces me to say "self" every other word doesn't strike me as particularly clever. 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).
- code_duck 16y agoI like 'self'. I don't mind it at all. 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)".
- xiongchiamiov 16y agoAh, but you are calling it with 3 parameters: 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-has-to-stay.html http://neopythonic.blogspot.com/2008/10/why-explicit-self-ha... .
- billmcneale 16y agoYes, this is exactly what I mean by "breaking programmer's expectations". Except maybe Modula, no language works like that at all. The parameters are in the parentheses, period. If you need to pass this, you do so in the declaration and in the invocation. If this is passed implicitly, you don't declare it in the parameters and you don't pass it at the call site. Python is doing this totally weird stuff that sits in the middle and that makes no logical sense at all. The fact that Python forces you to declare the "self" parameter is simply due to the fact that it's old, old, old. Nothing wrong with that, but post rationalizing it by saying it's okay to declare a method with 3 parameters but calling with just 2 is just silly.
- xiongchiamiov 16y agoSimply because it does not fit your expectations does not mean that it makes "no logical sense at all". As faulty beings, we often have expectations that really are quite far from logical.
- fleitz 16y agoThis is why I love F#. 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