本文最初发表于恋花蝶的博客(http://blog.csdn.net/lanphaday),如蒙转载,敬请何留全文完整,并连本声明一起转载。
凡是用过 Python的人,基本上都知道在交互式解释器中输入 import this 就会显示 Tim Peters 的 The Zen of Python,但它那偈语般的语句有点令人费解,所以我想分享一下我对它的体会,顺带给出我的翻译。
The Zen of Python, by Tim Peters
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.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
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.
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!
翻译和解释
|
|
比较恶搞的是,其实 this 模块的代码完全违背了这些原则,为了方便你查看它的代码,我把它贴出来
|
|
这段晦涩、复杂、凌乱的代码,莫非是 Tim Peters 提供的反例?
参考资料
[1] 《Python之禅》的翻译和解释