The Artima Developer Community
Sponsored Link

Weblogs Forum
Python 3K or Python 2.9?

62 replies on 5 pages. Most recent reply: May 8, 2008 9:17 AM by David Johnson

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 62 replies on 5 pages [ « | 1 2 3 4 5 | » ]
James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Python 3K or Python 2.9? Posted: Sep 11, 2007 6:22 AM
Reply to this message Reply
Advertisement
> Well, adding to Bruce and myself, Artima's recent article
> on "Python pain points" had four folks commenting on how
> they hated 'self'. Titus Brown's article on "5 things I
> hate about Python" had a fair number of complaints about
> 'self' as well, so much so that he actually comments "I'm
> impressed by how many people seem to hate 'self'." (since
> he personally likes it). A couple more Python users
> (including Bill de hOra) on jacobian.org's "Five Things I
> Hate about Python" commented that they hate 'self'.
>
> I'm not saying it's not needed ... obviously you need to
> designate scope inside your class methods. But I've
> actually seen people do 'item = self.item' inside their
> methods and then use the local variable instead just so
> they don't have to keep using 'self.' everywhere. That's a
> problem. Either it needs to be shorter, like Ruby's '@'
> symbol, or you need some other more convenient method to
> designate scope.

Well, you could always use 's' or 'y' or 'x' or 'caligula' instead of 'self'. That's what bothers me about it. It just seems like an afterthought. Yeah, it might clue people into how things really work but this isn't a turtle language, is it?

Morel Xavier

Posts: 73
Nickname: masklinn
Registered: Sep, 2005

Re: Python 3K or Python 2.9? Posted: Sep 11, 2007 8:35 AM
Reply to this message Reply
> Actually it was not purely via library constructs; there
> was a very important low-level change made to ensure cache
> coherency based on a seminal paper that came out in recent
> years and changed everyone's thinking about the issue (I
> don't have the reference, but Scott Meyers wrote about it,
> and I'm pretty sure Brian Goetz has as well).
>
Ok, thanks a lot. I stand half-corrected.

Guido van van Rossum

Posts: 359
Nickname: guido
Registered: Apr, 2003

Re: Python 3K or Python 2.9? Posted: Sep 11, 2007 10:16 AM
Reply to this message Reply
For more of my response, see http://www.artima.com/weblogs/viewpost.jsp?thread=214325

Lennart Regebro

Posts: 5
Nickname: regebro
Registered: Feb, 2006

Don't Get Rid of Self. Posted: Sep 11, 2007 11:54 AM
Reply to this message Reply
> self is inappropriate noise in a
> language that lays claim to clarity and simplicity.

NO! Self *is* clarity and simplicity. It's there. Like varaible. And you can use it. Self is the total and utter non-existance of magic.

And Ruby doesn't "take care of it" as you say. Instead of writing 'self.' you write '@'. That's no more taking care of it than Python. However, what it *is* is that it introduces an additional syntax feature. In python, once you understand foobar.bla, you will also understand self.bla, and the other way around.

Besides, using @ is ugly. ;)

And as to writing self first in a method, the benefit of that is that it again is explicit and easily understandable. The code does not get a magic self, or a magick @. The only magick is that self gets passed if it's a method. And this means methods and functions can be exactly the same. And are even replaceable with each other.

No, self is a thing of beauty.

> I'm hoping that this is just an issue of "waiting
> for maturity," but we need to make support for Python
> Eggs and Easyinstall part of the python distribution.

I totally agree.

The rest I have little strong opinions of. :-)

Michel Alexandre Salim

Posts: 4
Nickname: salimma
Registered: Sep, 2005

Re: Python 3K or Python 2.9? Posted: Sep 11, 2007 1:23 PM
Reply to this message Reply
Interesting mention of BeOS -- I was not aware of its "cheap process" design.

Linux is in that category as well -- I seem to recall Apache <= 1.3 having performance problems on Windows and Solaris, because it runs the daemon as multiple processes, which worked fine in Linux but is slow elsewhere.

Juergen Brendel

Posts: 8
Nickname: jbrendel
Registered: Sep, 2007

Re: Python 3K or Python 2.9? Posted: Sep 11, 2007 5:06 PM
Reply to this message Reply
Bruce: I fully agree with the points you made about the lack of true concurrency support in Python, and the fact that addressing this could really help Python to gain further adoption.

But I am wondering about your proposed agent based approach. The restriction to messages as the only means of communication between threads certainly makes them easy to write and maintain. However, even with today's threading module combined with the use of the standard queue, I can accomplish something very similar (albeit without concurrency support), as a previous poster already had pointed out.

As I have been trying to communicate, there are plenty of applications I can think of, where access to a shared data structure would be the more efficient means of solving a problem. Sending messages always comes with an overhead.

Sure, if you have shared data structures you will have to deal with all the usual issues. But it's possible to do that, and it has been done before. I would at least like to have the choice. If you don't want to deal with the shared data, you can still use threads and queues to get the agents you desire. Therefore, I would say that today's threading API is not bad, since it gives you the flexibility.

In the end, though, a simple, platform independent and standard (included) way to use agents or something similar is still preferable over what we have today. Since such an approach can be implemented as a library, it would have at least a chance to be available one day.

Roberto Bonvallet

Posts: 1
Nickname: rbonvall
Registered: Sep, 2007

Re: Python 3K or Python 2.9? Posted: Sep 11, 2007 8:59 PM
Reply to this message Reply
> Why don't we use just a leading dot?
> As .foo instead of self.foo?
>
> But I still can not appreciate the necessity to refer to
> the self argument in every method

Because self may not only be used to call its methods or to use its properties. Sometimes one needs to refer to the instance itself from within the method:

class C:
def method(self, a, b, c):
somefunction(x, y, z, self)

When this is not the case, there is a way to avoid the declaration of self in the signature: the _, syntax before the parameters:

class C:
def method(_, a, b, c):
....

Then you can use the _.foo syntax, which is not that different from the .foo that you propose.

So the language already supports it. But I still find that is more consistent all methods declaring self than treating methods differently according to whether they need to use the instance or not.

Cheers.

Alexander Belopolsky

Posts: 3
Nickname: alex
Registered: Mar, 2005

Re: Python 3K or Python 2.9? Posted: Sep 11, 2007 10:52 PM
Reply to this message Reply
It is not unheard of to use redundant this-> in C++ as a coding style that does not use a naminig convention such as mFoo for member variables. Just as with mandated indentation, Python's mandatory explicit self leads to fewer variations in coding styles.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Python 3K or Python 2.9? Posted: Sep 12, 2007 5:55 AM
Reply to this message Reply
> It is not unheard of to use redundant this-> in C++ as a
> coding style that does not use a naminig convention such
> as mFoo for member variables. Just as with mandated
> indentation, Python's mandatory explicit self leads to
> fewer variations in coding styles.

Except that 'self' is just a naming convention.

Thomas

Posts: 4
Nickname: tal197
Registered: Sep, 2005

Eggs and Easyinstall Posted: Sep 12, 2007 11:03 AM
Reply to this message Reply
Out of interest, what advantages do you see for "Eggs and Easyinstall", compared to Zero Install (http://0install.net)?

Cedric Beust

Posts: 140
Nickname: cbeust
Registered: Feb, 2004

Re: Python 3K or Python 2.9? Posted: Sep 12, 2007 11:46 AM
Reply to this message Reply
> But this scoping is explicit in Ruby as well; you merely
> say @foo instead of self.foo
>
> I understand preferring @foo (even though I personally
> prefer self.foo), but it doesn't seem terribly different
> to me.

It's fine in this context, but it's noise when declared in the signature of a method.

Like Bruce says, I'm inside a class, "self" (or this) should be implicit in this signature.

Another problem is that with self, I declare a function with three parameters but I invoke it with only two... go explain this to someone who learned OOP with Java.

--
Cedric
http://testng.org

Cedric Beust

Posts: 140
Nickname: cbeust
Registered: Feb, 2004

Re: Don't Get Rid of Self. Posted: Sep 12, 2007 11:57 AM
Reply to this message Reply
> > self is inappropriate noise in a
> > language that lays claim to clarity and simplicity.
>
> NO! Self *is* clarity and simplicity. It's there. Like
> varaible. And you can use it. Self is the total and utter
> non-existance of magic.

Magic is everywhere in programming languages (yes, even in Python), and it's not necessarily a bad thing.

In the early days of C, we simulated polymorphism by passing a pointer to the object as the first parameter of the function. It worked, but it was clearly a workaround caused by an inadequacy in the language.

C++ came along and created this magic parameter called "this" that gets silently passed to member functions so that we would no longer need to pass it explicitly everywhere (and yes, before that, plenty of other OO languages did the same with 'self' already). And our listings gained a lot in readability (they didn't lose anything either).

I think this kind of magic is good, and I wish it were available in Python as well.

I know that Guido assimilates criticism of "self" to that of "space indenting", so here is an idea: rename self "\t" and it will disappear from our listings.

Magic!

--
Cedric

Bruce Eckel

Posts: 875
Nickname: beckel
Registered: Jun, 2003

Re: Don't Get Rid of Self. Posted: Sep 13, 2007 11:37 AM
Reply to this message Reply
> Magic is everywhere in programming languages (yes, even in
> Python), and it's not necessarily a bad thing.
> Cedric

Magic is what programming languages are about. The better languages figure out what magic (that is, what abstractions) work better. To me, Python is more magical than most other languages.

If you're not writing in machine code, you're benefiting from the magic of your programming language.

Chuck Allison

Posts: 63
Nickname: cda
Registered: Feb, 2003

Re: Python 3K or Python 2.9? Posted: Sep 14, 2007 11:17 AM
Reply to this message Reply
Getting rid of self will mean getting rid of cls, and then we lose the uber simple way of automatically having class methods launch. I like self and cls - they simplify name lookup. The alternative seems to involve complicated lookup rules, and we don't want another C++/ADL-like situation in Python.

Dale Wilson

Posts: 2
Nickname: dalewilson
Registered: Sep, 2007

Re: Python 3K or Python 2.9? Posted: Sep 14, 2007 12:33 PM
Reply to this message Reply
Concerning the "self" debate.

Distinguishing between class members and "other" variables is valuable enough that several conventions have arisen over the years to do exactly that. In the Microsoft world (and those who copy it) members names start with "m_". In several other development cultures, member names end in '_'

"self" is not a keyword. It is a convention. If typing "self." is too much of a burden, you are free to use "m" as the name of the first argument. This lets you type m.myData. Compare and contrast this to m_myData or myData_ in the other conventions I mentioned. I don't think anyone is going to die of carpal tunnel syndrome here.

The point I'm trying to make is that "self" is not a wart on the language. It is an important programming concept that Python handles explicitly whereas other languages depend on convention and programmer discipline to handle [[Similar, for example, to having the program's indentation match its structure ]]

Long live self!

Flat View: This topic has 62 replies on 5 pages [ « | 1  2  3  4  5 | » ]
Topic: Python 3K or Python 2.9? Previous Topic   Next Topic Topic: Physical Dependencies

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use