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

简介: 探究当年为何Python3选择添加对Unicode标识符的支持. Find out why Python 3 chose to add support for non-ASCII identifiers.

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

Python2并不支持非ASCII码标识符. PEP的全称是Python Enhancement Proposal, 即Python增强提案. 这个3131提案创建于2007年5月. Python3于2008年12月发布.

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名了. 回应是库开发者有权根据需要进行设计, 这与其他制约因素(版权,文档是外文等等)类似. 开发者如果想要库被最广泛地使用, 自然会考虑到所有这些因素. 而这, 应该是开发者的决定, 而不是语言设计者的.

2017-11-30

相关文章
|
Python
Python中的标识符和保留字
Python中的标识符和保留字
51 0
|
自然语言处理 Python
Python:ULID通用唯一词典排序标识符
Python:ULID通用唯一词典排序标识符
309 0
|
6月前
|
JavaScript IDE 开发工具
python中的SyntaxError: invalid character in identifier(语法错误:标识符中有无效字符)
【5月更文挑战第14天】python中的SyntaxError: invalid character in identifier(语法错误:标识符中有无效字符)
512 8
|
2月前
|
Python
python标识符 | 10
python标识符 | 10
|
2月前
|
Python
Python ASCII码与字符相互转换
Python ASCII码与字符相互转换
|
4月前
|
存储 Python
语音输入,python数据类型,type()用来查看数据类型,数据类型转换,int(x)转整数,float(x)转换为浮点数,str(x),将对象转为字符串,标识符,标识符不允许使用关键字,关键字参考
语音输入,python数据类型,type()用来查看数据类型,数据类型转换,int(x)转整数,float(x)转换为浮点数,str(x),将对象转为字符串,标识符,标识符不允许使用关键字,关键字参考
|
6月前
|
Python
Python基础 笔记(三) 标识符、输入输出函数
Python基础 笔记(三) 标识符、输入输出函数
62 7
|
6月前
|
Java 程序员 编译器
初识Python(注释、代码缩进、编码规范、标识符、变量)
初识Python(注释、代码缩进、编码规范、标识符、变量)
107 2
|
6月前
02-python的基础语法-标识符/运算符/字符串拓展/字符串的拼接/字符串格式化/字符串精度控制/字符串格式化方式2/对表达式进行格式化/练习题/数据输入-input语句
02-python的基础语法-标识符/运算符/字符串拓展/字符串的拼接/字符串格式化/字符串精度控制/字符串格式化方式2/对表达式进行格式化/练习题/数据输入-input语句
|
6月前
|
Python
Python-标识符docx
Python-标识符docx
36 1