我希望python可以做的事情 [英] things I wish python could do

查看:58
本文介绍了我希望python可以做的事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很多时间使用python,而且就个人而言,我觉得它比使用java和c ++这样的语言要好得多,而且还有很多优点。 b $ b仍然是一些有损其优雅和灵活性的东西。我想b $ b我想可能会提到其中一些。我想听听人们对我投诉的看法是什么,我也想听听别人的抱怨。


1.很多关键词(例如:try / except)是严格必要的,并且不能在功能上下文中使用



这应该是可行的:map(print,mylist) )


2.没有简单的方法可以在外部扩展现有的类。


它可能,但它不是很好......


类形状:

def __init __(自我,数字,周长):

通过


目前你可以这样做:


形状.__ dict __。更新({

''triangle'':ClassMethod(

lambda self,sideLength:Shape(3,sideLength * 3))


''square'':ClassMethod(

lambda self,sideLength:Shape( 4,sideLength * 4))

})


我想要一种方法来扩展类,就像我可以定义它一样容易。


3.你无法扩展内置函数(字符串,列表等),你必须继承

他们。 Guido说他不会让我们因为它会产生兼容性问题,并可能打破翻译。也许如果我们有命名空间

功能,这不是一个问题?


4.分配不能在匿名函数内完成。


我认为大多数python程序员都会同意,python强调简单,可读性和一致性。最终,我认为这些东西中的任何一个都不足以证明减少灵活性,语法可变性和多功能性的合理性。我很惊讶

发现Ruby解决了我所有的python投诉,同时实现了与bthon相当的优雅和简洁,并提供了一个

一些创新的附加功能(包括真正的私人,公共和受保护的

方法)。


尽管事实上我不同意这一点哲学背后

prothon,我很高兴看到它,因为它激发了关于语言发展的良好对话

。 (只要那些心智闭合的人也会关闭他们的嘴巴也会闭嘴)


是否有任何强有力的理由说明为什么语言不应该支持

我列出的东西?是否有人知道未来python承诺的功能

版本可以解决或解决我的问题?我认为的任何问题是否真的只是无知的产品?

I''ve spent a lot of time using python, and personally, I feel like it is
vastly superior when compared to languages like java, and c++, but there
are still a few things that detract from its elegance and flexibility. I
thought I might mention a few of them. I''d like to hear what people think
of my complaints, and I also like to hear the complaints of others.

1. many keywords (eg:try/except) are strictly imperative, and cannot be
used in a functional context.

this really should be possible: map(print,mylist)

2. there is no easy way to extend existing classes externally.

its possible, but it aint pretty...

class Shape:
def __init__(self,numSides, perimeter):
pass

Currently you can do this:

Shape.__dict__.update({
''triangle'':ClassMethod(
lambda self,sideLength: Shape(3,sideLength*3))

''square'':ClassMethod(
lambda self,sideLength: Shape(4,sideLength*4))
})

I want a way to extend a class as easily as I can define it.

3. you cant extend the builtins (string,list,etc), you have to inherit
them. Guido says he wont let us because it would create compatability
issues, and possibly break the interpreter. Maybe if we had namespace
functionality, that wouldnt be an issue?

4. assignments cant be made inside of anonymous functions.

I think most python programmers will agree, that python emphasizes
simplicity, readability, and uniformity. Ultimately, I dont think that any
of those things are important enough to justify the reduction of
flexibility, syntactic mutability, and versatility. I was surprised to
find that Ruby solves all of my python complaints, while achieving
grace and simplicity easily comparable to that of python, and providing a
few innovative extras (including real private, public, and protected
methods).

Despite the fact that I disagree with quite a bit of the philosophy behind
prothon, I have enjoyed watching it, because it inspires good dialogue
about language development. (as long as those with closed minds keep their
mouths closed as well)

Are there are any strong reasons why a language shouldn''t support the
things I list? Is anybody aware of features promised for future python
versions that solve or nullify my problems? Are any of my perceived
problems really just products of ignorance?

推荐答案

Ryan Paul写道:
Ryan Paul wrote:
我花了很多时间使用python,而且个人而言,与java和c ++这样的语言相比,我觉得它非常优越,但是还有一些东西呢?这会降低其优雅性和灵活性。

1.许多关键词(例如:try / except)是严格要求的,不能在功能语境中使用。
Python是语句和表达式的语言。这不会改变。

如果您不喜欢这个功能,ml,lisp,(或者看起来像红宝石)将会更加符合您的喜好。 Python有一个必要的定义。一个纯粹的功能性的
系统在定义诸如打印之类的东西时会遇到问题。这是因为它们非常具有副作用。

这应该是可行的:map(print,mylist)
之后:

def print(* args):

print'',''。join(map(str,args))

你能做到:

地图(打印,mylist)

甚至:

打印(* mylist)

2.没有简单的方法从外部扩展现有的类。
它可能,但它不是很好......
类形状:
def __init __(self,numSides,perimeter):
传递
目前你可以这样做:
Shape .__ dict __。update({
''triangle'':ClassMethod(
lambda self,sideLength:Shape(3,sideLength * 3) )

''square'':ClassMethod(
lambda self,sideLength:Shape(4,sideLength * 4))
})
我想要一种方法尽可能轻松地扩展一个类。


好​​的,这是完全错误的。你绕着一个

的建筑走错了路,然后声称,这两扇门相距太远了。


class Shape:

def __init __(self,numSides,perimeter):

self.numSides = numSides

self.perimeter = perimeter

#这是,我期待你的意思)


Shape.triangle = classmethod(lambda klass,side:klass(3,side * 3))

Shape.square = classmethod(lambda klass,side:klass(4,side * 4))

甚至:

Shape .__ repr__ = lambda self:''Shape( %r,%r)''%(self.numSides,

self.perimeter)


使用上面的klass可以让你遵循以下代码: br $>
类FunnyShape(形状):

def avgSide(个体经营):

返回浮动(self.perimeter)/ self.numSides


然后你可以:

FunnyShape.triangle(5).avgSide()

3.你无法扩展内置类型(字符串,列表等等,你必须继承它们。 Guido说他不会让我们因为它会产生兼容性问题,并可能打破翻译。也许如果我们有命名空间功能,这不是一个问题?
不,投诉是关于影响全球环境

(从而使你导入的软件包不确定原始元素的行为)。

4.分配不能在匿名函数内完成。
这个想法是,通常匿名函数应该是微不足道的,或者你最好分别定义它们并为代码分配一个有意义的

名称。这样的代码在你编写它时需要付出更多的努力,

但是代码变得更具可读性。

我认为大多数python程序员会同意,python强调
简单性,可读性和一致性。
最终,我不认为任何这些事情都很重要,足以证明降低灵活性,语法可变性和多功能性。
I''ve spent a lot of time using python, and personally, I feel like it is
vastly superior when compared to languages like java, and c++, but there
are still a few things that detract from its elegance and flexibility.

1. many keywords (eg:try/except) are strictly imperative, and cannot be
used in a functional context. Python is a language of statements and expressions. This won''t change.
If you dislike this feature, ml, lisp, (or it seems, ruby) will be more
to your liking. Python has an imperative definition. A pure functional
system has problems defining things like "print" which, by their very
nature, cause side-effects.
this really should be possible: map(print,mylist) After:
def prints(*args):
print '', ''.join(map(str, args))
you can do:
map(prints, mylist)
or even:
prints(*mylist)
2. there is no easy way to extend existing classes externally.
its possible, but it aint pretty...

class Shape:
def __init__(self,numSides, perimeter):
pass
Currently you can do this:
Shape.__dict__.update({
''triangle'':ClassMethod(
lambda self,sideLength: Shape(3,sideLength*3))

''square'':ClassMethod(
lambda self,sideLength: Shape(4,sideLength*4))
})
I want a way to extend a class as easily as I can define it.

OK, this is just plain wrong. You are walking the wrong way around a
building and then claiming, "these two doors are too far apart."

class Shape:
def __init__(self,numSides, perimeter):
self.numSides = numSides
self.perimeter = perimeter
# which is, I expect what you meant)

Shape.triangle = classmethod(lambda klass, side: klass(3, side*3))
Shape.square = classmethod(lambda klass, side: klass(4, side*4))
and even:
Shape.__repr__ = lambda self: ''Shape(%r, %r)'' % (self.numSides,
self.perimeter)

Using klass above allows you to follow this code with:
class FunnyShape(Shape):
def avgSide(self):
return float(self.perimeter) / self.numSides

where you can then:
FunnyShape.triangle(5).avgSide()
3. you cant extend the builtins (string,list,etc), you have to inherit
them. Guido says he wont let us because it would create compatability
issues, and possibly break the interpreter. Maybe if we had namespace
functionality, that wouldnt be an issue? Nope, the complaint is about affecting the global environment
(thus making packages that you import unsure of the behavior of
the primitives).
4. assignments cant be made inside of anonymous functions. The idea is that generally anonymous functions should be trivial, or
you are better off separately defining them and assigning a meaningful
name to the code. Such code takes more effort at the time you write it,
but the code becomes much more readable.
I think most python programmers will agree, that python emphasizes
simplicity, readability, and uniformity.
Ultimately, I dont think that any of those things are important
enough to justify the reduction of flexibility, syntactic
mutability, and versatility.



然后你真的更喜欢ruby或smalltalk。如果你正在构建

非平凡的,长寿命的程序,你花费_far_更多时间阅读

代码而不是编写代码。灵活性很重要,但是不需要为了适应口味而做一些事情。混合样式的代码

是最难阅读的代码(除了机器生成的代码之外的
)。


我相信句法可变性是一个已经尝试过的想法,并且发现了b $ b。您可以定义的非标准语法越多,

您需要了解更多关于特定代码的信息才能读取它。
$ br />
至于多功能性,多功能性和灵活性的顶峰

是机器代码(不是那个笨拙的汇编程序)。我已经发现了很多我不会在python中做的事情,其中​​大部分都可以很容易地构建为扩展模块。


我见过太多interlisp和smalltalk代码集,而不是
使用彼此的模块。当你为了方便起见修改系统原语

时,很难使用

其他人不会分享你如何的特殊怪癖br />
修改基本系统。


编写代码超过三十年后,我发现python

有一种语言令人耳目一新系统具有清晰可辨,可信任的
可读结构。


很抱歉,如果这篇文章就是这个帖子的话,我会采取巨魔诱饵。 />

-

-Scott David Daniels
Sc *********** @ Acm.Org


Ryan Paul写道:
Ryan Paul wrote:
1.许多关键词(例如:try / except)是严格必要的,不能在功能上下文中使用。

这应该是可能的:map(print,mylist)
1. many keywords (eg:try/except) are strictly imperative, and cannot be
used in a functional context.

this really should be possible: map(print,mylist)




要使Python中的所有功能都可能是一个

h只有美容效果的努力。怎么样定义

例如


def fprint(item):

打印商品


将所有功能定义放在模块中''功能''

并使用它:


来自功能导入fprint


....

map(fprint,mylist)


Mit freundlichen Gruessen,

彼得马斯


-

-------------------------- -----------------------------------------

彼得Maas,M + R Infosysteme,D-52070 Aachen,Hubert-Wienen-Str。 24

电话+ 49-241-93878-0传真+ 49-241-93878-20电子邮件 pe********@mplusr.de

------------------------- ------------------------------------------



To make everything functional in Python would probably be a
huge effort with cosmetic effects only. What about defining
e.g.

def fprint(item):
print item

putting all functional definitions in a module ''functional''
and using it:

from functional import fprint

....
map(fprint, mylist)

Mit freundlichen Gruessen,

Peter Maas

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail pe********@mplusr.de
-------------------------------------------------------------------


Ryan Paul< se ******* @ sbcglobal.net>写道:
Ryan Paul <se*******@sbcglobal.net> writes:
我花了很多时间使用python,就个人而言,与java和c ++等语言相比,我觉得它非常优越。但是还有一些东西会影响它的优雅和灵活性。我想我可能会提到其中一些。我想听听人们对我的投诉的看法,我也想听听别人的抱怨。

1.很多关键词(例如:尝试/除外)都是严格的势在必行,不能在功能语境中使用。


是的,我发现整个声明表达二分法是一个巨大的PITA。

这真的应该是可能的:map(print,mylist)
< 2.没有简单的方法可以在外部扩展现有的类。

它可能,但它不是很好......

类形状:
def __init __(self,numSides,perimeter):
传递

目前你可以这样做:

形状.__字典__。更新({
''三角形'':ClassMethod(
lambda self,sideLength:Shape(3,sideLength * 3))
''square'':ClassMethod(
lambda self,sideLength:Shape( 4,sideLength * 4))
})


看起来像(我不知道ClassMethod是什么)一种冗长的方式

of wrting:


Shape.triangle = lambda self,sideLength:Shape(...))

我想要一种方法来扩展一个类很容易,因为我可以定义它。


你可以。有一种用于创建新类的语法,另一种用于改变现有类的

。 Ruby将两者混为一谈。


我认为你想要的是什么?是使用相同的语法来清除新类并使用相同的语法改变现有的类。也许你应该质疑

你是否真的想要它。


也许有一个令人满意的解决方案基于装饰者

在PEP 318中提出:


class Shape [更新]:

def三角形(self,sideLength):

。 ..

4.分配不能在匿名函数内完成。


实际上,在匿名函数中你可以做的很少,因为

你被限制为_single表达式。

我很惊讶地发现Ruby解决了我所有的python抱怨,同时实现了与python相当的优雅和简洁,并提供了一些创新的附加功能(包括真实的)私人,公共和受保护的方法)。


是的,访问受限的私有方法是该领域的一项创新

的程序员生产力降低,但它不是一项创新

Ruby的一部分......虽然为什么一种听起来很明智的语言,

会选择接受这种犯罪行为对我来说是一个谜。


(嗯...简要地阅读一本Ruby手册,我得到的印象是

其中一些是因为必须解决所有问题造成的问题

类继承了所有(可能的)全局函数...这让我

重新考虑我的声明,Ruby听起来很明智。)

有什么强有力的理由说明为什么一种语言不应该支持我列出的东西吗?


1)关键字是完全错误的。


4)Python的基于缩进的块结构使得一般匿名

功能有点问题。 (简单地仔细阅读PEP我注意到308

......我很惊讶它的发布日期不是4月1日,

因为它看起来像一个PERLification尝试。)

是否有人知道未来python版本承诺的功能
解决或消除我的问题?


阅读PEP。

我认为的任何问题都只是无知的产品吗?
I''ve spent a lot of time using python, and personally, I feel like it is
vastly superior when compared to languages like java, and c++, but there
are still a few things that detract from its elegance and flexibility. I
thought I might mention a few of them. I''d like to hear what people think
of my complaints, and I also like to hear the complaints of others.

1. many keywords (eg:try/except) are strictly imperative, and cannot be
used in a functional context.
Yes, I find the whole statement expression dichotomy one huge PITA.
this really should be possible: map(print,mylist)

2. there is no easy way to extend existing classes externally.

its possible, but it aint pretty...

class Shape:
def __init__(self,numSides, perimeter):
pass

Currently you can do this:

Shape.__dict__.update({
''triangle'':ClassMethod(
lambda self,sideLength: Shape(3,sideLength*3))

''square'':ClassMethod(
lambda self,sideLength: Shape(4,sideLength*4))
})
Which looks like (I don''t know what ClassMethod is) a long-winded way
of wrting:

Shape.triangle = lambda self, sideLength: Shape(...))
I want a way to extend a class as easily as I can define it.
You can. There is one syntax for creating new classes, and another for
mutating existing ones. Ruby conflates the two.

I think that what you "want" is to cleate new classes and mutate
existing ones using the same syntax. Perhaps you should question
whether you really want that.

Maybe there''s a satisfactory solution based on the decorators that are
being proposed in PEP 318:

class Shape [update]:
def triangle(self, sideLength):
...
4. assignments cant be made inside of anonymous functions.
Actually, there''s very little you can do in anonymous functions, given
that you are restricted to a _single expression_.
I was surprised to find that Ruby solves all of my python
complaints, while achieving grace and simplicity easily comparable
to that of python, and providing a few innovative extras (including
real private, public, and protected methods).
Yes, access-restricted private methods were an innovation in the field
of programmer productivity reduction, but it was not an innovation on
Ruby''s part ... though why a language which sounds quite sensible,
would choose to embrace such a criminal practice is a mystery to me.

(Hmm ... briefly perusing a Ruby manual, I get the impression that
some of it is a result of having to get around problems caused by all
classes inheriting all (would-be) global functions ... which makes me
reconsider my statement that Ruby sounds quite sensible.)
Are there are any strong reasons why a language shouldn''t support the
things I list?
1) Keywords are just plain wrong.

4) Python''s indentation-based block structure makes general anonymous
functions a bit problematic. (Briefly perusing the PEPs I notice 308
... and I''m surprised that it''s publication date is not April 1st,
as it looks like a PERLification attempt.)
Is anybody aware of features promised for future python versions
that solve or nullify my problems?
Read the PEPs.
Are any of my perceived problems really just products of ignorance?




可能。


我在一种充满争议的情绪中感受到了。你能说出来吗?


幸运的是,我已经在Python',Ruby'和你的脚趾上踩过:-)



Probably.

I''m feeling in a controversy-stirring mood. Can you tell?

With any luck I''ve trodden on Python''s, Ruby''s and your toes :-)


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

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