PEP 318 [英] PEP 318

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

问题描述




我在dev邮件列表上看过一些关于PEP 318的邮件并找到新的

语法真的很难看。


def foo [staticmethode](x,y):传递


我称之为foo(1,2),这对我来说并不直观!


我也不喜欢括号。


def foo(x,y)[staticmethode]:传递


更好,但我仍然看到[]作为列表或访问运算符而

不是吗?原始语法对我来说看起来更干净。


def foo(x,y)as staticmethode:pass


使用参数x和f定义foo y as staticmethode。


Python现在是C ++吗? Mabe我想念为什么这个语法错了。


问候


Marco

Hi

I have read some mail on the dev mailing list about PEP 318 and find the new
Syntax really ugly.

def foo[staticmethode](x, y): pass

I call this foo(1, 2), this isn''t really intuitive to me!

Also I don''t like the brackets.

def foo(x, y)[staticmethode]: pass

are better but still I used to see [] as list or access operator and the
don''t? The original Syntax looks much cleaner to me.

def foo(x, y) as staticmethode: pass

Define foo with arguments x and y as staticmethode.

Is Python now C++? Mabe I miss something why this syntax is wrong.

regards

Marco

推荐答案




Marco> def foo(x,y)[staticmethode]:传递

... vs ...

Marco> def foo(x,y)as staticmethode:pass


Marco>使用参数x和y定义foo作为staticmethode。


Marco> Python现在是C ++吗? Mabe我想念为什么这个语法错了。


我相信as wrap1,wrap2,...形式是

考虑的替代方案之一,虽然目前的情绪似乎有利于

类似列表的语法。


Python长期以来一直借用其他语言的好主意。我不知道这些是从C ++中借来的,不管它有什么语法与C ++的语法相似。请特别注意

结构比应用当前可用的

staticmethod和classmethod builtins更通用。最终的结果甚至不需要是一个

函数或类(已经讨论过将这个

构造应用于类,但它并没有那么明显的价值) 。有关其他一些想法,请参阅python-dev档案中最近的讨论。


Skip



Marco> def foo(x, y)[staticmethode]: pass
... vs ...
Marco> def foo(x, y) as staticmethode: pass

Marco> Define foo with arguments x and y as staticmethode.

Marco> Is Python now C++? Mabe I miss something why this syntax is wrong.

I believe the "as wrap1, wrap2, ..." form is one of the alternatives under
consideration, though current sentiment seems to be in favor of the
list-like syntax.

Python has a long history of borrowing good ideas from other languages. I''m
not aware that any of this is being borrowed from C++, no matter that it has
some syntactic similarities to stuff C++ does. Note in particular that the
construct is much more general than applying the currently available
staticmethod and classmethod builtins. The end result need not even be a
function or class (there has been some discussion about applying this
construct to classes, but it''s not as obviously valuable). See recent
discussion in the python-dev archives for some other ideas.

Skip

" Marco Bubke" <毫安*** @ bubke.de>在消息中写道

news:c3 ********* @ graf.cs.uni-magdeburg.de ...
"Marco Bubke" <ma***@bubke.de> wrote in message
news:c3*********@graf.cs.uni-magdeburg.de...

<我已经阅读了关于PEP 318的开发邮件列表上的一些邮件,发现
新的语法非常难看。
Hi

I have read some mail on the dev mailing list about PEP 318 and find the new Syntax really ugly.




似乎没有这是一个非常漂亮的

语法。那就是它在2.2中不是
的原因。

我的个人意见是我会拿任何

核心开发人员认为最好。


John Roth



There doesn''t seem to be a really beautiful
syntax for this. That''s the reason it wasn''t
in 2.2.

My personal opinion is that I''ll take whatever
the core developers decide is best.

John Roth


Marco Bubke写道:
Marco Bubke wrote:
def foo(x,y)as staticmethode:pass

使用参数x和y定义foo作为staticmethode。

Python现在是C ++吗? Mabe我想念为什么这个语法错了。
def foo(x, y) as staticmethode: pass

Define foo with arguments x and y as staticmethode.

Is Python now C++? Mabe I miss something why this syntax is wrong.




个人而言,我更喜欢as;另一个提议的语法(以及

大幅度)。但是,我觉得它让语言变得更加复杂,而且我很不确定它是否值得付出努力。我已经给了一些

的Python课程,并且在显示带有一些

方法的类时的第一反应是所以我猜第一个参数不是

命名为''self''它是一个类方法?所以我必须解释它不是

的情况等等。


如果简化类方法的创建是如此重要,我宁愿

a更激进的方法,最终结果会更直观

给新人:

- 给第一个参数未命名的所有方法发出警告自我

在下一版本的Python中。

- 在未来的主要版本的Python中,3或4,self成为关键字

和一个名为否则的第一个参数意味着一个类方法(我理解它可能意味着代码中没有使用self的很多变化)。


问候,


Nicolas



Personnally, I prefer the "as" syntax to the other proposed (and by a
large margin). However, I feel that it is making the language more
complex and I''m far from sure it''s worth the effort. I''ve given some
Python courses, and the first reaction when showing a class with some
methods is something like "so I guess when the first parameter is not
named ''self'' it makes a class method?". So I have to explain it''s not
the case, etc.

If easing the creation of class methods is so important, I would prefer
a more radical approach with a end result that would be more intuitive
to newcomers:
- Give a warning for all methods with first parameter not named "self"
in next versions of Python.
- In a future major version of Python, 3 or 4, self becomes a keyword
and a first parameter named otherwise implies a class method (I
understand it could mean a lot of changes in code not using self).

Regards,

Nicolas


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

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