为什么以及如何“只有一种方法可以做某事”? [英] Why and how "there is only one way to do something"?

查看:69
本文介绍了为什么以及如何“只有一种方法可以做某事”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



据我所知,Perl被称为有很多方法可以做什么? Python被称为只有一种方式。你能告诉我b $ b请解释一下吗?这怎么可能,它真的是*一个好的

概念?


As far as I know, Perl is known as "there are many ways to do
something" and Python is known as "there is only one way". Could you
please explain this? How is this possible and is it *really* a good
concept?

推荐答案



Tolga写道:

Tolga wrote:
据我所知,Perl被称为有很多方法可以做某些事情。 Python被称为只有一种方式。你能解释一下吗?这怎么可能呢?它真的是一个很好的概念吗?
As far as I know, Perl is known as "there are many ways to do
something" and Python is known as "there is only one way". Could you
please explain this? How is this possible and is it *really* a good
concept?




如果你要导入这个'',你会得到一些Python Zen ...我从这里获得了
这条线:

* ...

应该有一个 - 最好只有一个 - - 显而易见的方式。

.... *

如果这是你所指的,那么这里有一个解释。


所以没有只有一种方式,而是应该有一种方法可以做一些明显的,容易找到的,明显的,给定的 ...

在这里寻找的质量非常好*

1-你不会花费过多的时间来寻找对于它 -

你只需继续使用它,这样你的思维就可以集中在你需要实现的东西上,而不是你如何实现它。

2-如果它''显而易见'',那么其他人可能会看到它并使用它

也是如此在他们的代码中,其他人更容易理解。对于任何照顾过他人代码的
,这可能非常好*

;-)


Jean -Marc



if you ''import this'', you get a bit of Python Zen... from which I have
taken this line:
*...
There should be one-- and preferably only one --obvious way to do it.
....*
If this is what you are referring to then here is an explanation.

So there is not ''only one way'', but rather there should be a way to do
something that is obvious, re easy to find, evident, ''given''...
The quality(ies) looked for here that makes this *really* good is
1- that you don''t spend an inordinate amount of time looking for it -
you just go along and use it so your mind can be focussed of what you
need to achieve instead of how you can achieve it.
2- If it''s ''obvious'', then chances are others will see it and use it
also, so that their code is more understandable by others. For anyone
who has taken care of code of others this can be *really really good*
;-)

Jean-Marc




jmdescha ... @ gmail.com写道:

jmdescha...@gmail.com wrote:
Tolga写道:
据我所知,Perl被称为有很多方法可以做某事。 Python被称为只有一种方式。你能解释一下吗?这怎么可能呢?它真的是一个很好的概念吗?
As far as I know, Perl is known as "there are many ways to do
something" and Python is known as "there is only one way". Could you
please explain this? How is this possible and is it *really* a good
concept?


如果你要导入这个'',你会得到一些Python Zen ...来自我已经采取了这条线:
* ...
应该有一个 - 最好只有一个 - 明显的方式来做它。
... * <如果这是你所指的那么这里是一个解释。

所以没有只有一种方式,而是应该有一种方法可以做到
一些显而易见的东西,很容易找到,很明显,给定......
这里的品质(*)让这*真的很好*
1-你不要花费大量的时间来寻找它 -
你只需要去使用它,这样你的思维就可以集中在你需要实现的目标上而不是如何实现它。
2-如果它''显而易见'',那么其他人也很有可能会看到并使用它,这样他们的代码就更容易理解了。对于那些照顾别人代码的人来说,这真的很棒*
; - )



if you ''import this'', you get a bit of Python Zen... from which I have
taken this line:
*...
There should be one-- and preferably only one --obvious way to do it.
...*
If this is what you are referring to then here is an explanation.

So there is not ''only one way'', but rather there should be a way to do
something that is obvious, re easy to find, evident, ''given''...
The quality(ies) looked for here that makes this *really* good is
1- that you don''t spend an inordinate amount of time looking for it -
you just go along and use it so your mind can be focussed of what you
need to achieve instead of how you can achieve it.
2- If it''s ''obvious'', then chances are others will see it and use it
also, so that their code is more understandable by others. For anyone
who has taken care of code of others this can be *really really good*
;-)



我不太明白的是,如果它是显而易见的,是否有

a Zen,人们仍然会以这种方式编码(除非他们当然希望

将其隐藏起来或制作有目的地难以理解),

不会有任何争论哪一个是显而易见的方式。

如果有争论(或分歧),哪一个是显而易见的




我认为它更像是有一种首选的方式,用语言

创建者和那些人分享他的观点。


What I don''t quite understand is, if it is "obvious", whether there is
a Zen, people would still code it that way(unless of course they want
to hide it from others or make it difficult to understand on purpose),
there won''t be any argument of "which one is the obvious way".
And if there is an argument(or disagreement), which one is the obvious
?

I think it is more like there is a preferred way, by the language
creator and those share his view.


Tolga写道:
据我所知,Perl被称为有很多方法可以做某事 Python被称为只有一种方式。你能解释一下吗?这怎么可能呢?它真的是一个很好的概念吗?
As far as I know, Perl is known as "there are many ways to do
something" and Python is known as "there is only one way". Could you
please explain this? How is this possible and is it *really* a good
concept?



Perl的信条实际上是有多种方法可以做到这一点 ;,经常

缩写为TMTOWTDI。


(部分)Python的信条(您可以通过输入
<在上下文中阅读br />
导入此


在交互式命令提示符下)是应该有一个(并且

,最好只有一个)这样做。


显然,随着Python的改进(好吧,开发,无论如何:-)

执行旧任务的新方法将成为可能。因此,明显的方法是在文本文件的行上迭代

*使用*为


而1:

line = f.readline()

如果不是f:

休息

#处理线


现在它的价格为
for line in f:

#处理生产线


与所有的信条都应该用大量的盐和实用的空气来接近。与所有禅宗知识一样,重要的是

避免太过于字面意思地使用禅,否则可能需要在头部撞上你的b
坚持让你回到

enlightenment< 0.8 wink> ;.


我们尽量不要对这个群体的perlmongers粗鲁。毕竟,他们已经比我们到目前为止更接近世界统治了,他们不能用b $ b来帮助他们特别倾向于编码看起来像线条噪音。

[你可以看到,从

不时给他们带来一些好心情的乐趣]。


整体Python强调两个方面,可读性和可理解性,

作为主要值。可读性,可理解性和对新手的欢迎

方法...


问候

Steve

-

Steve Holden +44 150 684 7255 +1 800 494 3119

Holden Web LLC www.holdenweb.com

PyCon TX 2006 www.python.org/pycon/


Perl''s credo is actually "There''s more than one way to do it", often
abbreviated to TMTOWTDI.

(Part of) Python''s credo (which you can read in context by typing

import this

at an interactive command prompt) is "There should be one (and
preferably only one) way to do it".

Clearly as Python is improved (well, develops, anyway :-) new ways to
perform old tasks will become possible. So the obvious way to iterate
over the lines of a text file *used* to be

while 1:
line = f.readline()
if not f:
break
# process the line

whereas now it''s

for line in f:
# process the line

As with all credos this should be approached with a large-ish grain of
salt and a pragmatic air. As with all Zen knowledge it''s important to
avoid taking the Zen too literally, otherwise it may be necessary to hit
you on the side of the head with a stick to get you moving back towards
enlightenment <0.8 wink>.

We try not to be rude to perlmongers on this group. After all, they have
come much closer to world domination than we have so far, and they can''t
help their peculiar penchant for coding in what looks like line noise.
[As you can see it''s OK to poke a bit of good-humoured fun at them from
time to time].

Overall Python emphasises two things, readability and comprehensibility,
as primary values. Readability, comprehensibility and a welcoming
approach to newcomers ...

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/


这篇关于为什么以及如何“只有一种方法可以做某事”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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