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!
翻譯和解釋
基本上在解釋 clean code 的做法
優美優於醜陋,
明瞭優於隱晦;
簡單優於複雜,
複雜優於凌亂,
如果復雜不可避免,那代碼間也不能有難懂的關係,要保持接口簡潔
扁平優於嵌套,
稀疏優於稠密,
可讀性很重要!
即使實用比純粹更優,
特例亦不可違背原則。
錯誤絕不能悄悄忽略,
除非它明確需要如此。
面對不確定性,
拒絕妄加猜測。
任何問題應有一種,
且最好只有一種,
顯而易見的解決方法。
儘管這方法一開始並非如此直觀,
除非你是荷蘭人。
解決一個問題的方法可能會有很多種,但在Python中,只選擇最明顯的那一個
做優於不做,
然而不假思索還不如不做。
很難解釋的,必然是壞方法。
很好解釋的,可能是好方法。
命名空間是個絕妙的主意,
我們應好好利用它。
reference
- wiki
- PEP-20