PEP 318: Can't we all just get along?
Paul Morrow
pm_mon at yahoo.com
Wed Aug 18 18:50:59 EDT 2004
Michael J. Fromberger wrote:
> In article <mailman.1891.1092854353.5135.python-list at python.org>,
> Paul Morrow <pm_mon at yahoo.com> wrote:
>
>
>>Michael J. Fromberger wrote:
>>
>
>>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.
>
Actually, it illustrates the importance of proof-reading a post before
posting it, which I didn't (sorry). I should've also stated that the
Python developers would be told that this is a special version of Python
that automatically determines the type (static|class|instance) of a
method. In that light, do you see how effective the visual convention
can be?
>
>>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?
>
Then we have a bad convention. One that I would absolutely agree should
not be enforced by the system. But that's not the case here. I believe
that the obvious interpretation of code written with this convention
would consistently and reliably convey the authors intent:
* If method's first param is 'self', it's an instance method.
* If method's first param is 'cls' or 'klass', it's a class method.
* All other methods are static methods.
More information about the Python-list
mailing list