Decorators: an outsider's perspective
Paul Morrow
pm_mon at yahoo.com
Sun Aug 15 11:35:23 EDT 2004
Chas Emerick wrote:
> On August 14, 2004 9:35:48 AM EDT, Paul Morrow wrote:
>
>> def blah(a, b): # this is clearly a static method
>> pass
>>
>> def blah(self, a, b): # this is clearly an instance method
>> pass
>
>
> Ouch. Sorry, the arguments going into a function shouldn't have
> **anything** to do with the nature of that function. Overloading their
> existence, lack thereof, or their names as a way of describing the
> function they are hung off of seems like a horrible way to go. (Not to
> mention the fact that, at least conceptually, it is also violating that
> action-at-a-distance guideline...)
>
That reminds me of how I once thought about using indentation as a means
of denoting code blocks. How idiotic I thought that was. Now I realize
the elegance, beauty, 'genius' in that.
Because of the conventions widely used (in Python) today, the name of a
method's first formal parameter *does* indicate the type of method. If
you use 'self' as the name of your first parameter, the majority of us
will assume that that this is an instance method. If you don't use
'self', we will assume that it is not an instance method (unless you use
'this', and we happen to be familiar with languages where that stands
for the instance at hand, but then that is not the recommended
practice). So you see, when you write a method, you are telling us
something about it's type (or what type it isn't). You are overloading
the semantics of the first parameter.
Why don't we all just acknowledge that we are doing this? Why don't we
all just admit that a well written instance method uses 'self' as its
first argument. And well written static or class methods (as well as
plain ol' functions) don't use 'self'.
If we strive for well written (clear) code, we follow these conventions.
These conventions convey meaning as to the type of method. Therefore,
explicitly stating the type of method is both superfluous and a
potential source of confusion.
I believe that the problem many of us have with ideas like this is that
no other even semi-popular languages do this. But does that make it
wrong? Is our use of indentation wrong?
More information about the Python-list
mailing list