There is a large discussion on python-list about Guido's article about new self syntax, therefore I would like to use that to raise similar question: self in the body. Some time ago I was coding in Magik language (http://en.wikipedia.org/wiki/Magik_(programming_language), which is dynamically typed and similar to Smalltalk and actually to Python too - although the syntax is far less appalling. As you can see in the examples, defining methods is very similar to what Guido proposed in his blog, though you don't provide the name of the argument, but the name of the class. Then you just precede attributes with a '.', which is 4 letters less than self. And, well, this rocks ;-) It is really not a problem to type 4 letters (well, six with a coma and a space) in the signature, but it takes a lot of time to type all those selfs inside the function's body. So I was thinking, if this issue could be raised too, when new self syntax is proposed. Simple example looks like this: class bar: def bar.foo(): .x = 5 This could really save a lot of code, while attributes are still easily distinguishable. -- Filip Gruszczyński
On Tue, 9 Dec 2008 08:55:21 am Filip Gruszczyński wrote:
There is a large discussion on python-list about Guido's article about new self syntax, therefore I would like to use that to raise similar question: self in the body. Some time ago I was coding in Magik language (http://en.wikipedia.org/wiki/Magik_(programming_language), which is dynamically typed and similar to Smalltalk and actually to Python too - although the syntax is far less appalling. As you can see in the examples, defining methods is very similar to what Guido proposed in his blog, though you don't provide the name of the argument, but the name of the class. Then you just precede attributes with a '.', which is 4 letters less than self. And, well, this rocks ;-)
It is really not a problem to type 4 letters (well, six with a coma and a space) in the signature, but it takes a lot of time to type all those selfs inside the function's body.
For some definition of "a lot". I've just grabbed a random, heavily OO module from my own code library. It has 60 instances of "self", or 240 characters, out of 18,839 characters in total (including newlines). Removing self will decrease the number of my keystrokes and the amount of pure typing time (excluding thinking time, debugging time) by about 1.2%. I don't call that "a lot" -- it's actually quite small. And it becomes vanishingly trivial when you factor in that most of the time spent programming is not typing but thinking, testing, debugging, etc. Doing the same calculation for BaseHTTPServer.py and SimpleHTTPServer.py in the standard library, I get 1.9% and 2.0% respectively.
This could really save a lot of code, while attributes are still easily distinguishable.
I don't think so. -- Steven
I've just grabbed a random, heavily OO module from my own code library. It has 60 instances of "self", or 240 characters, out of 18,839 characters in total (including newlines). Removing self will decrease the number of my keystrokes and the amount of pure typing time (excluding thinking time, debugging time) by about 1.2%. I don't call that "a lot" -- it's actually quite small. And it becomes vanishingly trivial when you factor in that most of the time spent programming is not typing but thinking, testing, debugging, etc.
Well, maybe I don't program in Python the "right way" ;-), because it's a bit more in my code. I repeated this test, and for a random module holding some GUI stuff (built using PyQt) and it's more than 5% (213 selfs out of 16204 characters). With a small app for creating dungeon tiles for role playing games I astonishingly got same very similar value (484 * 4 / 35000) ;-) Maybe it's a feature of programming with a lot of gui stuff, which I do. But 1 of the 20 chars used for a self is quite a lot for me. -- Filip Gruszczyński
Filip Gruszczyński wrote:
There is a large discussion on python-list about Guido's article about
That discussion should stay there.
new self syntax, therefore I would like to use that to raise similar question: self in the body.
That has also be heavily discussed, many times, there and here.
... Then you just precede attributes with a '.',
Guido has specifically rejected that, more than once, I believe.
which is 4 letters less than self.
As has been said *many* times in previous discussions, you can use 1 letter intead of 4 if you really wish, if saving keystrokes is your highest priority. But please don't rehash these discussions, at least not here. Terry Jan Reedy
participants (3)
-
Filip Gruszczyński
-
Steven D'Aprano
-
Terry Reedy