Python之道

The Zen of Python  作者:Tim Peters(备注1)

Beautiful is better than ugly.

优美优于丑陋,

Explicit is better than implicit.

明了优于隐晦;

Simple is better than complex.

简单优于复杂,

Complex is better than complicated.

复杂优于凌乱;

Flat is better than nested.

扁平优于嵌套,

Sparse is better than dense.

稀疏优于稠密。

Readability counts.

可读性很重要!

Although practicality beats purity.

即使实用比纯粹更优,

Special cases aren’t special enough to break the rules.

特例亦不可违背原则。

Errors should never pass silently.

错误绝不能悄悄忽略,

Unless explicitly silenced.

除非它明确需要如此。

In the face of ambiguity, refuse the temptation to guess.

面对不确定性,拒绝妄加猜测。

There should be one– and preferably only one –obvious way to do it.

任何问题应有一种,且最好只有一种,显而易见的解决方法。

Although that way may not be obvious at first unless you’re Dutch. (备注2)

尽管这方法一开始并非如此直观,除非你是荷兰人。

Now is better than never.

做优于不做,

Although never is often better than *right* now.

然而不假思索还不如不做。

If the implementation is hard to explain, it’s a bad idea.

很难解释的,必然是坏方法

If the implementation is easy to explain, it may be a good idea.

很好解释的,可能是好方法。

Namespaces are one honking great idea — let’s do more of those!

命名空间是个绝妙的主意,我们应好好利用它。

备注1:Python之禅 最早由 Tim Peters在Python邮件列表中发表,它包含了影响Python编程语言设计的19条软件编写原则,在最初及后来的一些版本中,一共包含20条,其中第20条是“这一条留空(…)请Python作者Guido来填写”,这留空的一条从未公布也可能并不存在。

备注2:Tim这里是针对历史上Perl语言(其作者不是荷兰人)提倡一个问题有多种实现方式的灵活性即:There’s More Than One Way To Do It的特点提出来的,Python语言(其作者是荷兰人)只提倡“任何问题应有一种且最好只要一种显而易见的解决方法”从而保持语言统一的简洁性,所以说除非你是荷兰人(Python作者),否则你不容易直观看到这个方法(Tim就暗示Perl作者就没看到)。

发表评论

电子邮件地址不会被公开。 必填项已用*标注