python之禪 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之父1
動手比不動手要好
但不假思索就動手還不如不做
如果你的方案很難懂,那肯定不是一個好方案
如果你的方案很好懂,那肯定是一個好方案
命名空間非常有用,我們應當多加利用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章