@decorator syntax is sugar, but for what exactly?

Duncan Booth duncan.booth at invalid.invalid
Sun Aug 8 15:20:34 CEST 2004

Dan Sommers <me at privacy.net> wrote in 
news:m2u0vdj1bn.fsf at unique.fully.qualified.domain.name.yeah.right:

> On Sun, 8 Aug 2004 18:24:58 +1000,
> Anthony Baxter <anthonybaxter at gmail.com> wrote:
>> In many cases, these new features actually lead to smaller, simpler
>> code. I challenge _anyone_ to tell me that
>>   apply(func, args, kwargs) 
>> is better than 
>>   func(*args, **kwargs)
> Okay, I will.  The old way is better than the new way.
> Explicit is better than implicit, after all.
> Given your second example, is func the name of a function or an object
> that references a function?  Can I grep my source code to find a
> function named func?  (Okay, I'll find the variable named func, so at
> least I'll have some clue as to what's going on.)  Is there a "from
> module import func" statement in sight?  What happens when I look up
> "func" in the Python documentation to see if it's a built in name?

Why do you ask this about the second form only? func is a name that 
references a function in both cases. It doesn't matter whether that name 
was assigned directly with a def statement, or is the result of a 
subsequent binding.

> C did the same thing recently.
> Old C:  (*f)( argument );
> New C:  f( argument );
> With the old syntax, I knew immediately that f was a pointer to a
> function and that the function to which it pointed was being called
> indirectly.  With the new one, I have to track down a definition or
> declaration of f to see that. 

For 'recently' read 1987. In fact most C compilers probably implemented 
this feature before the ISO standard came out, but it was a feature of the 
first standardised version of C. I remember around that time being 
extremely glad that I could finally omit those extraneous parentheses.

More information about the Python-list mailing list