PEP 318装饰器不是装饰器 [英] PEP 318 decorators are not Decorators

查看:92
本文介绍了PEP 318装饰器不是装饰器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直非常感兴趣地关注装饰者辩论,并且花了相当长的时间来理解装饰者的意思。问题的一个问题是,Decorator模式更像是一个Unix管道而不是

它是PEP 318所称的装饰器。经典装饰器是运行时的,而不是定义时间,并且对基本功能没有破坏性。

PEP 318装饰器定义时间并且是对基础

函数的破坏性更改。例如,GoF书清楚地表明装饰者可能会在不影响基础课程的情况下添加或删除。


我个人认为这令人困惑重用装饰器名称为

不是经典装饰的东西。我也同意很多

评论,建议的语法并没有说明什么是

on是定义函数的一个有限转换。


Arien

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

推荐答案

星期五,2004年8月13日02:56:34 GMT,Arien Malec

< ar ********* @ yahoo.com.REMOVE>写道:
On Fri, 13 Aug 2004 02:56:34 GMT, Arien Malec
<ar*********@yahoo.com.REMOVE> wrote:
我一直在关注装饰者辩论,并且我花了相当长的时间来理解装饰者的意思。其中一个问题是,Decorator模式更像是一个Unix管道,而不是PEP 318称之为装饰器。经典装饰器是运行时,而不是定义时间,并且对基本功能没有破坏性。
PEP 318装饰器定义时间并且是对基本功能的破坏性改变。例如,GoF书清楚地表明,可以在不影响底层类的情况下添加或删除装饰器。


我首先想到用来描述mechansim的词是

不重要。 "装饰"对于Python来说,这意味着什么Python定义它意味着什么。


但是已经得出结论。实际上使用单词decorator

证明了语法的合理性,但是 - 正如你所说的那样 - 并没有以任何合理的方式描述该语法对

的影响。 />

我现在认为它有点像骗局。

我个人认为重复使用装饰器会让人感到困惑。
的名称不是经典的装饰者。我也同意许多评论意见,即所提出的语法并没有明确说明正在进行的是对定义函数的定向转换。


显然在声明性编程的世界中,它是犹太人的,因为
使@something意味着对函数的破坏性转换

已定义在它附近。用Python编程时。当然。并且

没有提供认知提示,或者没有必要通过参考任何其他符号来证明

本身。


那个先例当然开辟了一个新的可能性世界。


不幸的是。


艺术
Arien
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






Arien Malec写道:
Arien Malec wrote:
装饰。其中一个问题是装饰器模式更多
decorator. One of the issues is that the Decorator pattern is more



当前讨论中使用的术语装饰器来自编译器

写作。你有一个语法''树'',它''装饰''带有额外的

属性。


Daniel



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


" Daniel Dittmar" <哒************ @ sap.com>在新闻中写道:cfhsri
"Daniel Dittmar" <da************@sap.com> wrote in news:cfhsri


这篇关于PEP 318装饰器不是装饰器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆