Decorators: an outsider's perspective

Christophe Cavalaria chris.cavalaria at free.fr
Sat Aug 14 15:48:00 CEST 2004


Paul Morrow wrote:

> Chas Emerick wrote:
> 
> [...snip...]
>> 
>> The first time I saw this, I almost fell out of my chair:
>> 
>> def blah (args):
>> ....[insert 50/100/200 lines here]
>> blah = staticmethod(blah)
>> 
> 
> me too.
> 
> [...snip...]
>> 
>> So, when I see:
>> 
>> @staticmethod
>> def blah (args):
>> ....[insert 100 lines]
>> 
>> I say, YES!
> [...snip...]
> 
> I say, NO!  And I wonder why we feel a need to explicitly (and
> superflously) 'declare' something that is already clearly evident in the
> code (when recommended coding practices are followed).
> 
> class Foo:
>     def blah(a, b):         # this is clearly a static method
>        pass
> 
>     def blah(self, a, b):   # this is clearly an instance method
>        pass
> 
>     def blah(klass, a, b):  # this is clearly a class method
>        pass
> 
> Python was built (successfully) on the assumption that obvious
> interpretations of the code obviate the need for declarations.  Why
> wouldn't we continue with that mindset?
> 
> Paul

That remark is orthogonal to the problem at hand. staticmethod isn't the
only use for decorators although it's currently the most common example.
You are guilty of attacking the specific example instead of the general
idea behind it.

Of course, it doesn't mean that I don't like your idea. In fact, it find it
elegant except the the "klass" word which is ugly.




More information about the Python-list mailing list