Table of Contents
回复内容:
Home Backend Development Python Tutorial 如何用通俗易懂的语言解释《Flask 框架作者希望看到的 Python》到底在说什么?

如何用通俗易懂的语言解释《Flask 框架作者希望看到的 Python》到底在说什么?

Jun 06, 2016 pm 04:23 PM
flask python pythonpython

原文:Flask 框架作者希望看到的 Python

Python 真的有这种「最大的设计错误」吗?难道 Python 设计者看不到?「槽(slots)系统」真的很糟糕吗?

回复内容:

作者吐槽了Python语言与CPython解释器结合得过于紧密。甚至有时候CPython解释器的某些实现成为了语言的一部分。
虽说有语言规范,但是大多数情况下,它只是规定了解释器要做什么,甚至连这些都没有规定。

Python的问题在文章的“该死的解释器”一节有了一个直接的解释:
解释器把这些类型结构体直接暴露给Python代码。

比如,你写了一个BigInteger类(只是举例子而已)
<span class="k">class</span> <span class="nc">BigInteger</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="o">...</span>
    <span class="k">def</span> <span class="nf">__add__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">BigInteger</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">Value</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">Value</span><span class="p">)</span>
    <span class="o">...</span>
Copy after login
我认为作者的意思是,Python现在的发展模式是,公开搜集PEP,然后在现有基础上根据被采用的PEP打补丁,却几乎从来不对早起历史遗留下的解释器设计做调整和完善,并且几乎是针对CPython的。新特性越来越多,语言越来越复杂,老的问题一直没有改进,并且PSF致力于把一些历史遗留的烂设计解释成这是Python的哲学……与此同时,Python语言的文档其实是CPython的文档,于是乎其它实现,如Jython、PyPy、IronPython也不得不参照这些个奇怪的设计来做……

他举的例子,如slots的设计就是完全为了兼容了早期解释器把内置类型的一些方法而做的,以现在的角度来看完全没有必要……

再说GIL,如果按照python哲学,PSF说这么做更便于写C扩展什么的,说只需要一个解释器实体什么的,明明可以脱离GIL,并且别家也都这么做了,性能也确实能有很大改善,再说GIL带来的明显性能缺陷……没有任何道理把单解释器归到python哲学里……

大致如此吧…… 所以Python / Ruby这些编程语言基本上都是implement-driven而非specification-driven来设计的。

Ruby有过1.8到1.9的一次蜕变,整体上还算是好的。
当然你也会看到其他人在吐槽:Matz's Ruby Developers Don't Use RubySpec and It's Hurting Ruby 整篇文章的意思就是说:

Python明面上给了你一套标准,背地里自己老走后门;
操蛋的是,写得很多库之类的还特么依赖自己的后门儿,就算新来的,比如PyPy想走标准,也走不通了,最后也被迫走了后门;
更操蛋的是,他那个后门,开的也不是很高级,一堆缺陷。 首先,flask做的挺烂的,混乱的测试支持,没准的卡死问题。

然后,他提到的很多问题是框架设计层面的,比如slot,一般用户用不到,就算需要类似功能也可以有其他实现。

Python C层面确实很多问题,甚至我怀疑都不能算积重难返,而是故意拖延。Python3在几年前决定大规模重构,但很多核心问题还是扔在那里没动。比如GIL仍然是进程级的,而不是解释器级的。以当前状态看,如果有Python4的那天,肯定还是个不兼容的升级。

说说看而已,对正常的Python用户,这些讨论都没什么卵用。反正大家又用不上。 Slot 这一点没看出来有什么大不了的槽点,cpython 投机取巧又不是说别的解释器不能投机取巧了,无非就是语言规范散漫了点,比这更戳死人的槽点多了去了。
私以为,以 flask 那个样子,作者这种吐槽不用太当真,什么时候 bottle 作者也开始吐槽了再说吧。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Python vs. JavaScript: The Learning Curve and Ease of Use Python vs. JavaScript: The Learning Curve and Ease of Use Apr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Can vs code run in Windows 8 Can vs code run in Windows 8 Apr 15, 2025 pm 07:24 PM

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

Can visual studio code be used in python Can visual studio code be used in python Apr 15, 2025 pm 08:18 PM

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

How to run python with notepad How to run python with notepad Apr 16, 2025 pm 07:33 PM

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".

Is the vscode extension malicious? Is the vscode extension malicious? Apr 15, 2025 pm 07:57 PM

VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

See all articles