《Zen of python》---Python 之禪

《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之父

做總比不做好

但不假思索的做還不如不做

如果你的方案很難懂,那肯定是一個糟糕的方案

如果你的方案很好懂,那肯定是一個好方案

命名空間時一個響亮的傑出創意---那就讓我們多使用它們吧!

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