为什么不在 Python 代码中使用 Ωβλδεαθφψωϕϖ(非 ASCII 字符)?
Why not to use Ωβλδεαθφψωϕϖ (non-ASCII chars) in Python code?
..我发现在 python 中编写非常“数学重”的函数时,使代码更具可读性(至少对我而言)的一种方法是尽可能严格地遵循文献,包括使用希腊字母,如Ω、θ、φ、ψ、ω、φ等
代码按预期工作,但 PyCharm 突出显示这些字符并显示“标识符中的非 ASCII 字符”。
..没有引用任何 PEP(Python 编码标准)。
我要就为什么我应该避免在标识符中使用非 ASCII 字符提出清醒的论据。
因为它们不包含在标准的 qwerty 键盘中,在您的代码中继续引用它们会很麻烦。
你最好只用它们的 ascii 等价物(字符串 alpha
等)来引用它们,并让现代 ide 中的智能感知处理输入。
如果您正在寻找鼓舞人心的标准,您可能需要 PEP 3131
Should identifiers be allowed to contain any Unicode letter?
Drawbacks of allowing non-ASCII identifiers wholesale:
- Python will lose the ability to make a reliable round trip to a
human-readable display on screen or on paper.
- Python will become vulnerable to a new class of security exploits; code and submitted
patches will be much harder to inspect.
- Humans will no longer be able
to validate Python syntax.
- Unicode is young; its problems are not yet well understood and solved; tool support is weak.
- Languages with non-ASCII identifiers use different character sets and normalization
schemes; PEP 3131's choices are non-obvious.
- The Unicode bidi algorithm yields an extremely confusing display order for RTL text when digits or operators are nearby.
当然这已经被接受所以它是 pycharm 的决定,而不是 pep.
..我发现在 python 中编写非常“数学重”的函数时,使代码更具可读性(至少对我而言)的一种方法是尽可能严格地遵循文献,包括使用希腊字母,如Ω、θ、φ、ψ、ω、φ等
代码按预期工作,但 PyCharm 突出显示这些字符并显示“标识符中的非 ASCII 字符”。
..没有引用任何 PEP(Python 编码标准)。
我要就为什么我应该避免在标识符中使用非 ASCII 字符提出清醒的论据。
因为它们不包含在标准的 qwerty 键盘中,在您的代码中继续引用它们会很麻烦。
你最好只用它们的 ascii 等价物(字符串 alpha
等)来引用它们,并让现代 ide 中的智能感知处理输入。
如果您正在寻找鼓舞人心的标准,您可能需要 PEP 3131
Should identifiers be allowed to contain any Unicode letter?
Drawbacks of allowing non-ASCII identifiers wholesale:
- Python will lose the ability to make a reliable round trip to a human-readable display on screen or on paper.
- Python will become vulnerable to a new class of security exploits; code and submitted patches will be much harder to inspect.
- Humans will no longer be able to validate Python syntax.
- Unicode is young; its problems are not yet well understood and solved; tool support is weak.
- Languages with non-ASCII identifiers use different character sets and normalization schemes; PEP 3131's choices are non-obvious.
- The Unicode bidi algorithm yields an extremely confusing display order for RTL text when digits or operators are nearby.
当然这已经被接受所以它是 pycharm 的决定,而不是 pep.