318装饰器不是装饰器

318装饰器不是装饰器

本文介绍了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

推荐答案








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

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

属性。


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



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

08-21 11:35