1. 程式人生 > >Python 的經典設計格言,格言來源於 Python 但不限於 Python

Python 的經典設計格言,格言來源於 Python 但不限於 Python

sil itl ability practical sum enc 好想 guess space

The Zen of Python, by Tim Peters

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!

譯文:

美麗優於醜陋。

清楚優於含糊。
簡單優於復雜。
復雜優於繁瑣。
平坦優於曲折。
寬松優於密集。
重要的是可讀性。
特殊的案例不足以特殊到破壞規則。
盡管實踐可以打破真理。
錯誤卻不可置之不理。
除非另有明確要求。
面對模棱兩可,拒絕猜測。
總會有一個 —— 最好是只有一個 —— 顯而易見的方式來明辨。
哪怕這種方式在開始的時候可能並不明顯 —— 除非你是荷蘭人 (作者Guido von Rossum是荷蘭人)。
現在有比沒有好。
盡管沒有經常好於現在。
如果如何實現很難被解釋清楚,那麽這個想法就是一個壞想法。
如果如何實現可以被很好的解釋,那麽這是一個好想法。
命名空間就是一個非常好的想法 —— 讓我們在這方面多做些工作吧!

Python 的經典設計格言,格言來源於 Python 但不限於 Python