News for hackers. Stuff that matters.
Re:Python's Mutable Default Problem by itsnotvalid on Sunday February 20, 2011 @12:53PM (#2242471)
So indeed the auth of the article is really too clever on this.
Re:Python's Mutable Default Problem by xiongchiamiov on Sunday February 20, 2011 @01:20PM (#2242583)
And 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.

Re:Python's Mutable Default Problem by code_duck on Sunday February 20, 2011 @03:19PM (#2242899)
That'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.
Re:Python's Mutable Default Problem by chc on Sunday February 20, 2011 @04:25PM (#2243141)
Python 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.
Re:Python's Mutable Default Problem by billmcneale on Sunday February 20, 2011 @06:11PM (#2243459)
A 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).

Re:Python's Mutable Default Problem by xiongchiamiov on Sunday February 20, 2011 @07:10PM (#2243619)
Ah, 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-ha... .

Re:Python's Mutable Default Problem by billmcneale on Sunday February 20, 2011 @10:25PM (#2244131)
Yes, 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.

Re:Python's Mutable Default Problem by xiongchiamiov on Monday February 21, 2011 @04:38AM (#2244866)
Simply 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.
Re:Python's Mutable Default Problem by code_duck on Sunday February 20, 2011 @11:17PM (#2244239)
I 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)".

Re:Python's Mutable Default Problem by fleitz on Sunday February 20, 2011 @07:13PM (#2243625)
This 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
Re:Python's Mutable Default Problem by code_duck on Sunday February 20, 2011 @11:11PM (#2244230)
You can rename self to whatever you want in Python by changing it in the function definition.

    class Flip(object):
        foo=4
        def flop(x,num):
            x.bar=x.foo+num
Re:Python's Mutable Default Problem by xiongchiamiov on Monday February 21, 2011 @04:37AM (#2244863)
Right, but his point was that the self variable is declared in front of the method name, similarly to how it looks when you call said method.
Re:Python's Mutable Default Problem by jbri on Sunday February 20, 2011 @05:04PM (#2243273)
Python is "clever" so that the Python programmer doesn't have to be.
Re:Python's Mutable Default Problem by eru on Sunday February 20, 2011 @05:19PM (#2243328)
Actually Python has pretty close correspondence between source code and compiled byte code.