1
0
wiki/Tech/programming-language/Python/文化/设计哲学.md

87 lines
1.8 KiB
Markdown
Raw Permalink Normal View History

2022-10-18 20:08:11 +08:00
---
title: 设计哲学
description: Python 的设计哲学
keywords:
2023-11-09 17:30:33 +08:00
- Python
- 设计哲学
2022-10-18 20:08:11 +08:00
tags:
2023-11-09 17:30:33 +08:00
- Python/文化
2024-04-26 21:42:22 +08:00
- 技术/程序语言
2022-10-18 20:08:11 +08:00
author: 7Wate
date: 2022-10-18
---
```python
# 运行此语句
# 控制台输出显示 Python 之禅
import this
```
## The Zen of Python, by Tim Peters
Python 之禅,蒂姆·彼得斯 (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!
命名空间是个绝妙的主意,我们应好好利用它。