《Zen of python》是Tim Peters 为 Python 语言总结的软件开发禅宗,也是Python或任何一门开发语言使用过程中应当注意或借鉴的经典原则。可以使用Python 交互模式解释器通过输入“import this”命令获取。原文描述如下:
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!
中文翻译如下:
优美优于丑陋
明确优于隐晦
简单优于复杂
复杂优于混乱
扁平优于嵌套
稀疏优于紧凑
可读性应当被重视
没有任何特例可以打破这些规则
虽然现实往往不那么完美
但是不应该放过任何异常
除非你确定需要如此
面对不确定,杜绝猜测
肯定有一种
通常也是唯一种最佳的解决方案
虽然这并不容易,因为你不是Python之父
做总比不做好
但不假思索的做还不如不做
如果你的方案很难懂,那肯定是一个糟糕的方案
如果你的方案很好懂,那肯定是一个好方案
命名空间时一个响亮的杰出创意---那就让我们多使用它们吧!