使Python走向Effective系列目錄

Effective以一詞,並不僅僅侷限於執行速度層面的高效率,同時有着令代碼易於閱讀、易於測試且易於維護等意思,此外,它還蘊藏着易於擴展、易於修改和易於多人協做等更爲高階的理念。若是可以經過一些具體的條目來培養一套分析並解決問題的思路,那就能夠更加深入地體會Python語言的設計哲學及實踐藝術。不少Python開發者都崇尚Pythonic編程方式,這種Pythonic方式不只應該體如今代碼風格和項目規範之中,並且更應該體如今思惟模式和架構設計層面,這一點,我想也Effective追求者嚮往的本質的東西。html

Python之蟬 by Tim peterspython

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 以編寫優美的代碼爲目標)

明瞭勝於晦澀(優美的代碼應當是明瞭的,命名規範,風格類似)

簡潔勝於複雜(優美的代碼應當是簡潔的,不要有複雜的內部實現)

複雜勝於凌亂(若是複雜不可避免,那代碼間也不能有難懂的關係,要保持接口簡潔)

扁平勝於嵌套(優美的代碼應當是扁平的,不能有太多的嵌套)

間隔勝於緊湊(優美的代碼有適當的間隔,不要奢望一行代碼解決問題)

可讀性很重要(優美的代碼是可讀的)

即使假借特例的實用性之名,也不可違背這些規則(這些規則至高無上)

不要包容全部錯誤,除非你肯定須要這樣作(精準地捕獲異常,不寫 except:pass 風格的代碼)

當存在多種可能,不要嘗試去猜想

而是儘可能找一種,最好是惟一一種明顯的解決方案(若是不肯定,就用窮舉法)

雖然這並不容易,由於你不是 Python 之父(這裏的 Dutch 是指 Guido )

作也許好過不作,但不假思索就動手還不如不作(動手以前要細思量)

若是你沒法向人描述你的方案,那確定不是一個好方案;反之亦然(方案測評標準)

命名空間是一種絕妙的理念,咱們應當多加利用(倡導與號召)

Effective Python系列目錄架構

 

相關文章
相關標籤/搜索