为什么人们使用 Python?—— 软件质量

未匹配的标注

软件质量

Python 是故意实现了简单可读的语法和高度一致的编程模型。就像以前一个 Python 会议的口号证明的那样,最终结果是 Python 似乎“适合你的大脑”——也就是,语言的特性以一致和有限的方式进行交互,并且从一小组核心概念自然地延伸出来,这使得语言更容易学习、理解和记忆。在实践中, Python 程序员在读写代码的时候不需要不断地去参考手册。它是一个设计一致的系统,以至于许多人发现产生了令人惊讶的一致代码。

在哲学上, Python 采用了一个有点极简主义的方法。这意味着,虽然通常完成一个编程任务有多种方法,但是通常只有一个自然的方法,一些不太明显的替代方法和在语言中无处不在的少数交互(解决问题的一致方法)。并且 Python 不会为你做出任何的决定。当交互是模糊的时候,明确的干预比“魔法”更可取。以 Python 的方式思考,显式比隐式更好,简单比复杂更好[4]。

除了这些设计主题(简洁易读和一致性),Python 包括如模块和 OOP 这样自然促进代码可重用性的工具,并且因为 Python 关注质量,所以很自然Python 程序员也是这样。


注[4]:为了更全面地了解 Python 哲学,在任意的 Python 交互提示光标处,键入命令 import this,这会调用 Python 中隐藏的一个复活节彩蛋——隐藏在 Python 下面的一系列的设计理念,它们遍布整个语言和它的用户社区。在其中,首字母缩写词 EIBTI 是 “显式比隐式更好” 规则的当前的流行行话。这些原则不是宗教信仰,但是已经近似于 Python 的箴言和信念,我们会在本书中经常引用它们。

$ python
Python 3.10.8 (main, Oct 13 2022, 10:17:43) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 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!
>>>

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
讨论数量: 0
发起讨论 只看当前版本


暂无话题~