细分PEP318的方法 [英] Breakdown of approaches to PEP318

查看:41
本文介绍了细分PEP318的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是大部分讨论语法的细分:PEP318使用来自python-dev的

示例。可能还有几个(我已添加[10])。

该示例同时应用了函数修饰和注释。

#[1] .. [3] ,竞争方式说同样的事情


#[1]

def foo(self)[attrs(spark_rule =" DOC:= HEAD BODY FOOT" ;,

url =" / cgi-bin / directory / directory"),

publish_to_web]:

" doc string" < br $> b $ b身体

#[2]

def foo [attrs(spark_rule =" DOC:= HEAD BODY FOOT",

url =" / cgi-bin / directory / directory"),

publish_to_web](self):

" doc string" < br $> b $ b身体

#[3]

def [attrs(spark_rule =" DOC:= HEAD BODY FOOT",br />
url =" / cgi-bin / directory / directory"),

publish_to_web] foo(self):

" doc string"

身体

#[4]现在一次用''as'' - 在你的''最喜欢''中的子:'"使用&qu ot;,with,...

def foo(self)as attrs(spark_rule =" DOC:= HEAD BODY FOOT",\

url =" / cgi-bin / directory / directory"),\

publish_to_web:

" doc string"

body

#[5]函数属性字典

def foo(self)[publish_to_web]:

{spark_rule:" DOC:= HEAD BODY FOOT" ,

url =" / cgi-bin / directory / directory"}

" doc string"

body

#[6] @function_attribute = ...

def foo(self)[publish_to_web]:

@ spark_rule =" DOC:= HEAD BODY FOOT"

@ url =" / cgi-bin / directory / directory"

" doc string"

body

#[7]:function_attribute:...

def foo(self)[publish_to_web]:

:spark_rule:" DOC:= HEAD BODY FOOT"

:url:" / cgi-bin / directory / directory"

" doc string"

身体


#[8]特殊目的区块 - 提出了几种变体

这个:

spark_rule =" DOC:= HEAD BODY FOOT使用:

publish_to_web

def foo(self):

" doc string"

body

#[9]某种形式的文档字符串滥用 - 一个语法选项...

def foo(self):

""" doc string

@:

foo.spark_rule =" DOC:= HEAD BODY FOOT",

foo.url =" / cgi-bin / directory / directory")

foo = publish_to_web(foo)

""

body


#[10]元类方法 - 仅在内部工作班级

decorate(" foo",publish_to_web,

spark_rule =" DOC:= HEAD BODY FOOT",

url =" / cgi-bin / directory / directory")

def foo(self):

" doc string"

身体


#[11]当前方法

def foo(self):

" doc字符串

非常



身体

....

foo .spark_rule =" DOC:= HEAD BODY FOOT",

foo.url =" / cgi-bin / directory / directory")

foo = publish_to_web(foo )


就个人而言,我发现所有这些都非常令人不快。我发现这些

提案都不干净,清晰和/或可读,除了[11](首先是整个混乱的开始)。我倾向于同意以下内容,

有点断章取义,备注:

"""

如果我们只能学习来自他人的错误:


最后,在设计Self时,我们通过犯错误吸取了一课:

示例可以说服设计师包含其他功能

后来结果在不可预见的情况下产生难以理解的行为。这可能被称为语言设计者的陷阱。

极简主义,简单性和一致性是更好的指南。它们使每个

程序员受益,而不仅仅是需要高级功能的程序员。我们怀疑今天的许多面向对象语言都可以通过降低功能来获利。


编程作为一种体验:对自我的启发

"""

Isaac Gouy,http://lambda.weblogs.com/discuss/msgReader$11653

Here''s a breakdown of most of the syntax discussed re: PEP318 using an
example from python-dev. There are probably several more (I''ve added [10]).
The example applies both function decoration and annotation.
# [1] .. [3], competing ways to say the same thing

# [1]
def foo(self) [attrs(spark_rule="DOC := HEAD BODY FOOT",
url="/cgi-bin/directory/directory"),
publish_to_web]:
"doc string"
body

# [2]
def foo[attrs(spark_rule="DOC := HEAD BODY FOOT",
url="/cgi-bin/directory/directory"),
publish_to_web](self):
"doc string"
body

# [3]
def [attrs(spark_rule="DOC := HEAD BODY FOOT",
url="/cgi-bin/directory/directory"),
publish_to_web] foo(self):
"doc string"
body
# [4] now once with ''as'' - sub in your ''favourite'': "using", "with", ...
def foo(self) as attrs(spark_rule="DOC := HEAD BODY FOOT", \
url="/cgi-bin/directory/directory"), \
publish_to_web:
"doc string"
body
# [5] function attribute dictionary
def foo(self)[publish_to_web]:
{spark_rule:"DOC:= HEAD BODY FOOT",
url="/cgi-bin/directory/directory"}
"doc string"
body
# [6] @function_attribute = ...
def foo(self)[publish_to_web]:
@spark_rule="DOC:= HEAD BODY FOOT"
@url="/cgi-bin/directory/directory"
"doc string"
body
# [7] :function_attribute:...
def foo(self)[publish_to_web]:
:spark_rule:"DOC:= HEAD BODY FOOT"
:url:"/cgi-bin/directory/directory"
"doc string"
body

# [8] special purpose blocks - several variations proposed
with this:
spark_rule = "DOC:= HEAD BODY FOOT"
url = "/cgi-bin/directory/directory"
using:
publish_to_web
def foo(self):
"doc string"
body
# [9] some form of doc string abuse - one syntax option ...
def foo(self):
"""doc string
@:
foo.spark_rule="DOC:=HEAD BODY FOOT",
foo.url="/cgi-bin/directory/directory")
foo = publish_to_web(foo)
"""
body

# [10] metaclass approach - only works inside classes
decorate("foo", publish_to_web,
spark_rule="DOC:=HEAD BODY FOOT",
url="/cgi-bin/directory/directory")

def foo(self):
"doc string"
body

# [11] current method
def foo(self):
"doc string"
very
long
body
....
foo.spark_rule = "DOC:=HEAD BODY FOOT",
foo.url="/cgi-bin/directory/directory")
foo = publish_to_web(foo)

Personally, I find all of this very off-putting. I find none of these
proposals clean, clear, and/or readable, except perhaps [11] (which started
the whole mess in the first place). I tend to agree with the following,
somewhat out of context, remark:
"""
If only we could learn from others'' mistakes:

Finally, in designing Self, we have learned one lesson by making mistakes:
examples can persuade the designer to include additional features which
later turn out to produce incomprehensible behavior in unforeseen
circumstances. This might be called the language designer''s trap.
Minimalism, simplicity and consistency are better guides. They benefit every
programmer, not just the ones who need advanced features. We suspect that
many of today''s object-oriented languages could profit by dropping features.

Programming as an Experience: The Inspiration for Self
"""
Isaac Gouy, http://lambda.weblogs.com/discuss/msgReader$11653

推荐答案

11653
11653


还有一个:


#[12]基于
< a rel =nofollowhref =http://mail.python.org/pipermail/python-dev/2004-March/043613.html\"target =_ blank> http://mail.python.org/pipermail /pyt...ch/043613.html

[publish_to_web]

def foo(self):

{spark_rule: DOC:= HEAD BODY FOOT,

url =" / cgi-bin / directory / directory"}

" doc string"

body
One more:

# [12] based on
http://mail.python.org/pipermail/pyt...ch/043613.html
[publish_to_web]
def foo(self):
{spark_rule:"DOC:= HEAD BODY FOOT",
url="/cgi-bin/directory/directory"}
"doc string"
body


最后一个有错误,这里又是:


[publish_to_web]

def foo(self):

{spark_rule:" DOC:= HEAD B ODY FOOT",

url:" / cgi-bin / directory / directory" }

" doc string"

body


That last one had an error, here it is again:

[publish_to_web]
def foo(self):
{spark_rule:"DOC:= HEAD BODY FOOT",
url:"/cgi-bin/directory/directory" }
"doc string"
body



这篇关于细分PEP318的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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