PEP 318: Can't we all just get along?
Michael J. Fromberger
Michael.J.Fromberger at Clothing.Dartmouth.EDU
Wed Aug 18 17:49:23 EDT 2004
In article <mailman.1891.1092854353.5135.python-list at python.org>,
Paul Morrow <pm_mon at yahoo.com> wrote:
> Michael J. Fromberger wrote:
>
> > In article <mailman.1858.1092832530.5135.python-list at python.org>,
> > Paul Morrow <pm_mon at yahoo.com> wrote:
> >> class Foo:
> >> def method1(self, a, b): pass # clearly an instance method
> >> def method2(cls, a, b): pass # clearly a class method
> >> def method3(a, b): pass # clearly a static method
> >
> > I think this is a terrible idea. What you are proposing is essentially
> > that Python should assign special meaning to the identifiers "self" and
> > "cls" when they appear as the first variable in a method definition
> > inside a class. I am having a hard time thinking of anything LESS in
> > the spirit of Python, short of writing in unstructured BASIC.
>
> 'self' already has a special meaning to experienced Python developers,
> by virtue of its role in the recommended coding practices.
That's true: And note, that its special meaning is interpreted not by
the Python translator, but by the Python programmer. It is my feeling
that it should remain thus.
> And if you ask experienced Python developers who understand the
> difference between class, static, and instance methods, to guess what
> kind of method this is...
>
> def foo(cls, a, b): pass
>
> ...I bet the majority would correctly guess "class".
Well, given just that definition, the guess would be incorrect. The
current release of Python would also require:
def foo(cls, a, b): pass # As defined above
foo = classmethod(foo)
Otherwise, it would be an instance method, not a class method. I hope
this illustrates why visual conventions are not always as obvious as
they seem, and should not be cast into the concrete of implementation.
> Right. So a convention becomes a rule. Sounds like a natural
> evolution.
And just like in natural evoluation, not all mutations are desirable. ;)
> Declarations aren't needed when an obvious interpretation of the code
> conveys the desired meaning.
What about when the obvious interpretation of the code does NOT convey
the desired meaning?
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
More information about the Python-list
mailing list