V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xuanwu
V2EX  ›  分享发现

Python3 选择支持非 ASCII 码标识符的缘由

  •  
  •   xuanwu · 2018-08-05 10:40:45 +08:00 · 1460 次点击
    这是一个创建于 2320 天前的主题,其中的信息可能已经有所发展或是发生改变。

    原文在: PEP 3131 -- Supporting Non-ASCII Identifiers.

    Rationale 一节开篇明义, 指出 用母语命名标识符对代码清晰度和可维护性的提高.

    Python code is written by many people in the world who are not familiar with the English language, or even well-acquainted with the Latin writing system. Such developers often desire to define classes and functions with names in their native languages, rather than having to come up with an (often incorrect) English translation of the concept they want to name. By using identifiers in their native language, code clarity and maintainability of the code among speakers of that language improves.

    下面列出了一些质疑和回应. 其中:

    People claim that they will not be able to use a library if to do so they have to use characters they cannot type on their keyboards. However, it is the choice of the designer of the library to decide on various constraints for using the library: people may not be able to use the library because they cannot get physical access to the source code (because it is not published), or because licensing prohibits usage, or because the documentation is in a language they cannot understand. A developer wishing to make a library widely available needs to make a number of explicit choices (such as publication, licensing, language of documentation, and language of identifiers). It should always be the choice of the author to make these decisions - not the choice of the language designers.

    简要翻译:

    有人表示库如果是其他语言命名, 不懂这一语言的使用者就不会输入 API 名了. 回应是库开发者有权根据需要进行设计, 这与其他制约因素(版权,文档是外文等等)类似. 开发者如果想要库被最广泛地使用, 自然会考虑到所有这些因素. 而这, 应该是开发者的决定, 而不是语言设计者的.

    注: 原文是知乎专栏"中文编程"的Python3 选择支持非 ASCII 码标识符的缘由

    第 1 条附言  ·  2018-08-05 13:16:04 +08:00
    Python2 并不支持非 ASCII 码标识符. PEP 的全称是 Python Enhancement Proposal, 即 Python 增强提案. 这个 3131 提案创建于 2007 年 5 月. Python3 于 2008 年 12 月发布.
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5518 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 19ms · UTC 02:00 · PVG 10:00 · LAX 18:00 · JFK 21:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.