List some possible reasons why arriving at consensus about decorators has
been so hard (or impossible) to acheive. There are certainly more. Are these the killers?
This commit is contained in:
parent
03d428dbde
commit
5cac22671f
35
pep-0318.txt
35
pep-0318.txt
|
@ -78,6 +78,41 @@ modifications to classes. For Python 2.4, only function/method
|
||||||
decorators are being added.
|
decorators are being added.
|
||||||
|
|
||||||
|
|
||||||
|
Why Is This So Hard?
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
A couple decorators (``classmethod()`` and ``staticmethod()``) have
|
||||||
|
been available in Python since version 2.2. It's been assumed since
|
||||||
|
approximately that time that some syntactic support for them would
|
||||||
|
eventually be added to the language. Given this assumption, one might
|
||||||
|
wonder why it's been so difficult to arrive at a consensus.
|
||||||
|
Discussions have raged off-and-on at times in both comp.lang.python
|
||||||
|
and the python-dev mailing list about how best to implement function
|
||||||
|
decorators. There is no one clear reason why this should be so, but a
|
||||||
|
few problems seem to be most problematic.
|
||||||
|
|
||||||
|
* Disagreement about where the "declaration of intent" belongs.
|
||||||
|
Almost everyone agrees that decorating/transforming a function at
|
||||||
|
the end of its definition is suboptimal. Beyond that there seems to
|
||||||
|
be no clear consensus where to place this information.
|
||||||
|
|
||||||
|
* Syntactic constraints. Python is a syntactically simple language
|
||||||
|
with fairly strong constraints on what can and can't be done without
|
||||||
|
"messing things up" (both visually and with regards to the language
|
||||||
|
parser). There's no obvious way to structure this information so
|
||||||
|
that people new to the concept will think, "Oh yeah, I know what
|
||||||
|
you're doing." The best that seems possible is to keep new users
|
||||||
|
from creating a wildly incorrect mental model of what the syntax
|
||||||
|
means.
|
||||||
|
|
||||||
|
* Overall unfamiliarity with the concept. For people who have a
|
||||||
|
passing acquaintance with algebra (or even basic arithmetic) or have
|
||||||
|
used at least one other programming language, much of Python is
|
||||||
|
intuitive. Very few people will have had any experience with the
|
||||||
|
decorator concept before encountering it in Python. There's just no
|
||||||
|
strong preexisting meme that captures the concept.
|
||||||
|
|
||||||
|
|
||||||
Background
|
Background
|
||||||
==========
|
==========
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue