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!
译文:(AI 翻译)
优美胜于丑陋。 明了胜于晦涩。 简洁胜于复杂。 复杂胜于繁琐。 扁平胜于嵌套。 留白胜于紧凑。 可读性很重要。 特殊情况不足以打破规则。 尽管实用胜于纯粹。 错误绝不应悄然忽略。 除非明确地忽略它们。 面对不确定时,拒绝猜测的诱惑。 解决问题的方法应该有一个——最好只有一个——明确的方式。 虽然这方式起初可能不明显,除非你是荷兰人。 现在做胜于不做。 但盲目行动不如不行动。 难以解释的实现是个坏主意。 易于解释的实现可能是个好主意。 命名空间是个绝妙的主意——让我们多使用它们!
说明:
- 第 14 条:“unless you’re Dutch” 是对 Python 之父 Guido van Rossum 国籍的幽默引用,暗示 Python 的某些设计对母语者更直观。
- 第 16 条:“never is often better than right now” 强调避免仓促行动,与中文“三思而后行”类似。
- 第 19 条:“honking great” 是俚语,译为“绝妙的”以保留语气。