Guido's new method definition idea
acerimusdux at comcast.net
Sun Dec 7 08:49:27 CET 2008
Russ P. wrote:
> Python already uses shorthand extensively. How about "def"? For people
> who are so worried about self-explanatory symbols, what the heck does
> that stand for? Default? Defeat? Defect? Defunct? Defer?
I think the difference here is that those other abbreviations are
mostly fairly standard. The "def" keyword is the same in Ruby, and
similar enough to "define" or "defun" in Scheme or LISP. The "!="
operator is pretty much standard across nearly all languages. What is
being proposed with "$" here though, would be different from how it is
used anywhere else and would be confusing.
Moreover, I especially don't like proposing to eliminate as well in this
instance the "dot notation", which is standard in nearly all object
oriented languages. Using something as a substitute for "self" is one
thing, and you can mostly use what you like there now, as "self" is more
a convention than a requirement. But the "dot" that belongs there is
critical to understanding, you can't hide that to save one keystroke.
Getting back to Guido's suggestion, though, I think it makes some sense.
Being new to Python, I did find myself occasionally forgetting "self" in
instance methods. But, I also thought the requirement to include it was
helpful in reminding me what was really going on there, that I was
creating an instance method which was really a function that wouldn't
actually be created until the instance was initiated. I tend to think
this may be clearer though using the dot notation rather than passing
the instance variable as a parameter.
I'm not sure though whether allowing both syntaxes would make things
more or less confusing. It might actually be helpful in some respects
for newcomers to realize that self.method(arg) is somewhat the same as
method(self, arg). Perhaps I'm wrong on this, I don't fully understand
yet what is going on under the hood, but it seems to me that that would
be part of the glue that allows Python to be so multi-paradigm; much of
the difference between OOP and procedural or functional is just
different syntax for the same thing.
More information about the Python-list