Python之禅

2019-05-15 周三 by Tim Peters. 黄复雄.

《Python之禅》是2004年的Python改进提案,编号为PEP 20。禅诗、偈颂的形式。黄复雄译。

摘要

老资格的Python人Tim Peters将仁慈独裁者(BDFL)1的Python设计指导原则简明扼要地归纳成20条警句,只有其中19句被记载下来。

Python之禅 / The Zen of Python

美好于丑。 / 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.
虽说开始的时候它可能并非显然——除非你是荷兰人[^Rossum]。 / 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!

  1. 指Python创始人,荷兰人吉多·范罗苏姆(Guido van Rossum)。 


Fork me on GitHub