PyTips
Python 之禪與 Pythonic
Python 之禪是 Python 語言的設(shè)計哲學(xué)與所倡導(dǎo)的編程理念董瞻,Pythonic 則是指基于 Python 理念編寫更加符合 Python 語法習(xí)慣(idiomatic Python)的代碼搁胆,這也是本項目所追求的目標(biāo)谋旦,因此以本篇作為開頭污桦。
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 之禪,by Tim Peters
優(yōu)美勝于丑陋
明確勝于隱晦
簡單勝于復(fù)雜
復(fù)雜勝于凌亂
扁平勝于嵌套
稀疏勝于緊湊
可讀性至關(guān)重要
即便特例,也需服從以上規(guī)則
除非刻意追求晦溪,錯誤不應(yīng)跳過
面對歧義條件,拒絕嘗試猜測
解決問題的最優(yōu)方法應(yīng)該有且只有一個
盡管這一方法并非顯而易見(除非你是Python之父)
動手勝于空想
空想勝于不想
難以解釋的實現(xiàn)方案挣跋,不是好方案
易于解釋的實現(xiàn)方案三圆,才是好方案
命名空間是個絕妙的理念,多多益善避咆!