Python 的编程哲学
你可以在 Python IDLE 中键入如下命令:
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!
中文译本如下:
Python之禅
- Tim Peters
1. 美优于丑。
2. 直白优于隐晦。
3. 简单优于复杂。
4. 复杂优于纠结。
5. 扁平优于嵌套。
6. 稀疏优于稠密。
7. 可读性是有重要价值的。
8. 特例可以有,但不能特例到打破规则。
9. 尽管在纯粹性和实用性之间倾向的是实用性。
10. 出错决不能无声无息地忽略。
11. 除非明确地说明了是无声无息的。
12. 面对二义性情况时,要拒绝任何猜的诱惑。
13. 一件事应该一种做法 —— 并且宁愿只有一种做法 —— 一种显而易见的做法。
14. 尽管在刚开始的时候这个做法可能不是那么显而易见,毕竟你不是荷兰人。
15. 『现在』优于『决不』。
16. 尽管『决不』常常优于『马上』。
17. 如果一个实现难于解释清楚,那它是个差的想法。
18. 如果一个实现很容易解释清楚,那它可能是个好的想法。
19. 命名空间是个拍案叫绝的想法 — 放手多多用起来吧!