473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PEP 318 decorators are not Decorators

I've been following the decorator debate with some interest, and it's taken
me a reasonably long time to understand what is meant by a decorator. One
of the issues is that the Decorator pattern is more like a Unix pipe than
it is what PEP 318 calls a decorator. The classic decorator is run-time,
rather than define time, and is non-destructive to the base function. The
PEP 318 decorator is define time and is a destructive change to the base
function. For instance, the GoF book makes it clear that decorators may be
added or removed without affecting the underlying class.

I personally think it's confusing to reuse the "Decorator" name for
something that is not a classic decorator. I also agree with the many
comments that the proposed syntax does not make it clear that what is going
on is a destuctive transformation of the defined function.

Arien
Jul 18 '05 #1
11 1526
On Fri, 13 Aug 2004 02:56:34 GMT, Arien Malec
<ar*********@yahoo.com.REMOVE> wrote:
I've been following the decorator debate with some interest, and it's taken
me a reasonably long time to understand what is meant by a decorator. One
of the issues is that the Decorator pattern is more like a Unix pipe than
it is what PEP 318 calls a decorator. The classic decorator is run-time,
rather than define time, and is non-destructive to the base function. The
PEP 318 decorator is define time and is a destructive change to the base
function. For instance, the GoF book makes it clear that decorators may be
added or removed without affecting the underlying class.
I had first thought that the word used to describe the mechansim was
unimportant. "decorator" would come to mean, for Python, what Python
defined it to mean.

But have concluded otherwise. In fact using the word "decorator"
justifies the syntax, but - as you say - does not describe the impact
of that syntax in any reasonable way.

Its a bit of a con, I now think.

I personally think it's confusing to reuse the "Decorator" name for
something that is not a classic decorator. I also agree with the many
comments that the proposed syntax does not make it clear that what is going
on is a destuctive transformation of the defined function.
Apparently in the world of declarative programming it is kosher to
make @something mean a destructive transformation of a function
defined in its vicinity. When programming in Python. of course. And
without providing a cognative hint, or without the need to justify
itself by reference to any other notation that ever was.

That precedent, of course, opens up a world of new possibilities.

Unfortunately.

Art
Arien


Jul 18 '05 #2
Arien Malec wrote:
decorator. One of the issues is that the Decorator pattern is more


The term decorator as used in the current discussion comes from compiler
writing. You have a syntax 'tree' which gets 'decorated' with additional
attributes.

Daniel
Jul 18 '05 #3
"Daniel Dittmar" <da************@sap.com> wrote in news:cfhsri$a1q$1
@news1.wdf.sap-ag.de:
Arien Malec wrote:
decorator. One of the issues is that the Decorator pattern is more


The term decorator as used in the current discussion comes from compiler
writing. You have a syntax 'tree' which gets 'decorated' with additional
attributes.


1) That's not mentioned in PEP 318
2) That's in disagreement with
http://www.python.org/moin/PythonDecorators
3) Won't most programmers think GoF decorators before compiler syntax tree
decorators?

Arien
Jul 18 '05 #4
On 2004-08-13, Arien Malec <ar*********@yahoo.com.REMOVE> wrote:
decorator. One of the issues is that the Decorator pattern is more


The term decorator as used in the current discussion comes
from compiler writing. You have a syntax 'tree' which gets
'decorated' with additional attributes.


1) That's not mentioned in PEP 318
2) That's in disagreement with http://www.python.org/moin/PythonDecorators
3) Won't most programmers think GoF decorators before compiler syntax tree
decorators?


Thank you! I spent a while reading up on "decorators" the
other day and was completely baffled. I couldn't see that the
stuff in PEP 318 discussion threads had anything at all to do
with what was discussed by the references I found on
"decorators" (which were all about "design pattern" stuff).
So, I gave up and went back to work on writing a strip-chart
recorder using the Gnuplot module.

--
Grant Edwards grante Yow! I'm shaving!! I'M
at SHAVING!!
visi.com
Jul 18 '05 #5

1) That's not mentioned in PEP 318

We can fix that.

2) That's in disagreement with http://www.python.org/moin/PythonDecorators

That too (different authors, by the way).

Arien> 3) Won't most programmers think GoF decorators before compiler
Arien> syntax tree decorators?

Not if they are unfamiliar with the GoF patterns (myself included).

Skip
Jul 18 '05 #6
Skip Montanaro <sk**@pobox.com> wrote in
news:ma**************************************@pyth on.org:
Arien> 3) Won't most programmers think GoF decorators before
compiler syntax tree decorators?

Not if they are unfamiliar with the GoF patterns (myself included).


Google:

decorate "syntax tree" -pattern --> 129 hits
decorator "syntax tree" -pattern --> 20 hits
decorator pattern -"syntax tree" --> about 62,000 hits

Arien
Jul 18 '05 #7

Arien> 3) Won't most programmers think GoF decorators before
Arien> compiler syntax tree decorators?

Skip> Not if they are unfamiliar with the GoF patterns (myself included).

Arien> Google:

...

BFD. Sure, there are tons more application programmers in the world than
compiler geeks, so Google returns many more hits for GoF-style decorators.
So? The thing is, just because in a verbal Rohrschach test you think "GoF"
when someone says "decorator" doesn't mean everybody else will (or should).
Hell, when someone says "decorator" I usually think of "Queer Eye for the
Straight Guy". <wink>

now-where-were-my-fabric-swatches?-ly, y'rs,

Skip
Jul 18 '05 #8
Skip Montanaro <sk**@pobox.com> wrote in
news:ma**************************************@pyth on.org:

Arien> 3) Won't most programmers think GoF decorators before
Arien> compiler syntax tree decorators?

Skip> Not if they are unfamiliar with the GoF patterns (myself
included).

Arien> Google: [~62,000 : ~130 mentions of each sort of decorator]

...

BFD.... The thing is, just because in a verbal Rohrschach
test you think "GoF" when someone says "decorator" doesn't mean
everybody else will (or should).


Clearly, Python can choose any name for the auto-function-transformation
syntax in question, but it's rather willfully confusing to choose a name
that's heavily identified with a profoundly different semantics that's
superficially similar in intent.

Arien
Jul 18 '05 #9


Arien Malec wrote:
Skip Montanaro <sk**@pobox.com> wrote in
news:ma**************************************@pyth on.org:

Arien> 3) Won't most programmers think GoF decorators before
Arien> compiler syntax tree decorators?

Skip> Not if they are unfamiliar with the GoF patterns (myself
included).

Arien> Google: [~62,000 : ~130 mentions of each sort of decorator]

...

BFD.... The thing is, just because in a verbal Rohrschach
test you think "GoF" when someone says "decorator" doesn't mean
everybody else will (or should).

Clearly, Python can choose any name for the auto-function-transformation
syntax in question, but it's rather willfully confusing to choose a name
that's heavily identified with a profoundly different semantics that's
superficially similar in intent.

Arien

This is especially confusing as, in everyday english usage, to decorate
is not the same as to transform.

Perhaps "transform" could be consdered as an alternative.

The Mad Hatter's response to Alice dealt with the root naming issue:
"When I use a word," Humpty Dumpty said in rather a scornful tone. "It
means just what I choose it to mean - neither more or less."

"The question is," said Alice, "whether you can make words mean so
many different things."
"The question is," said Humpty Dumpty, "which is to be master - that's
all."

Colin W.

Jul 18 '05 #10
On Sun, 15 Aug 2004 18:29:52 GMT, Arien Malec
<ar*********@yahoo.com.REMOVE> wrote:
Skip Montanaro <sk**@pobox.com> wrote in
news:ma**************************************@pyt hon.org:

Arien> 3) Won't most programmers think GoF decorators before
Arien> compiler syntax tree decorators?

Skip> Not if they are unfamiliar with the GoF patterns (myself
included).

Arien> Google: [~62,000 : ~130 mentions of each sort of decorator]

...

BFD.... The thing is, just because in a verbal Rohrschach
test you think "GoF" when someone says "decorator" doesn't mean
everybody else will (or should).

Correct. I would think simply that "decorate" would be descriptive in
its own right.

As obscure as the GOF reference might be to some, the alternative
references justifying the naming seem to be off the map in terms of
obscurity. So let's assume a blank slate. And all we want is the
word to be descriptive.

And it seems to me the naming is in fact descriptive - but of the
syntax, not the functionality.

Which is OK, I guess, if we accept it as that.

As there are already a number of compromises being made in the
addition of this to the language, I just think of this as one more.

Clearly, Python can choose any name for the auto-function-transformation
syntax in question, but it's rather willfully confusing to choose a name
that's heavily identified with a profoundly different semantics that's
superficially similar in intent.


Again, a little different if we think of it as describing the syntax,
not the functionality. Yes the ambiguity, I agree, is bad. And yes,
I agree, willful, to an extent. Or at least willful to the extent that
there is little interest in truly justifying the choice of
terminology, and specifung whether we are referencing the syntax or
the functionality in the choice of the terminology.

This ambiguity is to the essence of decorators, maybe both as syntax
and as functionailty. But it is not the first time I have issues with
python-dev folks using ambiguity as gloss.

Art

Jul 18 '05 #11
"Colin J. Williams" <cj*@sympatico.ca> wrote in
news:Ns******************@news20.bellglobal.com:
Arien Malec wrote:
Clearly, Python can choose any name for the
auto-function-transformation syntax in question, but it's rather
willfully confusing to choose a name that's heavily identified with a
profoundly different semantics that's superficially similar in
intent.
This is especially confusing as, in everyday english usage, to
decorate is not the same as to transform.

Perhaps "transform" could be consdered as an alternative.


That would be my leaning, as well. Ideally, the name would make it clear
that the application order of the transformations is significant....

Arien
Jul 18 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Sparks | last post by:
Anyway... At Europython Guido discussed with everyone the outstanding issue with decorators and there was a clear majority in favour of having them, which was good. From where I was sitting it...
17
by: daishi | last post by:
For what it's worth: As far as I know, the proposed @decorator syntax will be the first time that two logical lines of python with the same indentation will not be independent of one another....
8
by: Michele Simionato | last post by:
Decorators can generate endless debate about syntax, but can also be put to better use ;) Actually I was waiting for decorators to play a few tricks that were syntactically too ugly to be even...
4
by: RebelGeekz | last post by:
Just my humble opinion: def bar(low,high): meta: accepts(int,int) returns(float) #more code Use a metadata section, no need to introduce new messy symbols, or mangling our beloved visual...
2
by: Guido van Rossum | last post by:
Robert and Python-dev, I've read the J2 proposal up and down several times, pondered all the issues, and slept on it for a night, and I still don't like it enough to accept it. The only reason...
0
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
13
by: km | last post by:
Hi all, was going thru the new features introduced into python2.4 version. i was stuck with 'decorators' - can someone explain me the need of such a thing called decorators ? tia KM
11
by: Helmut Jarausch | last post by:
Hi, are decorators more than just syntactic sugar in python 2.x and what about python 3k ? How can I find out the predefined decorators? Many thanks for your help, Helmut Jarausch
2
by: Andrew West | last post by:
Probably a bit of weird question. I realise decorators shouldn't be executed until the function they are defined with are called, but is there anyway for me to find all the decorates declared in a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.