为什么非 ASCII 字符在函数 / var 名称中仍然不受欢迎?
当我看到一个为一些学生编写的小程序时,我经常看到这样的内容:(haskell,德语):
ueber = "What the haeck!"
而不是像
über = "What the häck!"
许多现代语言都指定允许通过 UTF-8 在声明名称中使用非标准字符一样,有吗在项目中避免这些字符的特殊原因,这肯定只适用于能够输入这些字符的人(例如德国学生团队?)或者这只是一个历史原因?
我知道,如果您在国际范围内开发应用程序,则应该将名称保留在 a-zA-Z_0-9
中,但是有什么理由在“本地”项目中避免这种情况吗?
When I see a small program which is written for some students, I often see something like this: (haskell, german):
ueber = "What the haeck!"
instead of
über = "What the häck!"
As many modern languages are specified to allow non-standard charactes in declaration names via UTF-8, is there a special reason for avoiding these in a project, which is sure to be only for people who are able to input these characters (say for a team of german students?) or is this just a historical reason?
I know, that you should keep names in a-zA-Z_0-9
if you develop an applicaio internationally, but are there any reason for avoiding this in a "local" project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
,这当然是主要原因。我想到的其他原因是许多开发工具、搜索功能、编辑器、解析器、文档记录器、代码搜索引擎等不会期望代码中出现非 ASCII 输入。
此外,您永远不知道有一天您的代码可能会在哪里使用!最小的无辜学校项目可以成长为一个很好的开源工具,有一天会在全球范围内使用。在这种情况下,ASCII 是最小公分母,至少目前是这样。
That is certainly the main reason. Other reasons that come to mind is that many development tools, search functions, editors, parsers, documentors, code search engines etc. will not expect non-ASCII input in code.
Also, you never know where your code may be used one day! The smallest innocent school project can grow into a nice Open-Source tool that gets used around the globe one day. In that case, ASCII is the smallest common denominator, at least at the moment.
我必须参与一个由法国开发商发起的项目。当越来越多的人加入该项目时,他们不得不花费大量时间将程序翻译成英语。预先教您的德国学生本课,他们不仅能够与其他人共享代码,而且也不再需要
über
或ueber
变量。顺便说一句,ü 是一个字母字符。
+
和-
是非字母数字的,我想说这很明显为什么它们在函数名称中不受欢迎。I've had to work on a project started by French developers. They had to spend quite a bit of time translating their program to English when more people joined the project. Teach your German students this lesson up front, and not only will they be able to share their code with others, they'll no longer need an
über
orueber
variable either.BTW, ü is an alphabetic character.
+
and-
are non-alphanumeric, and I'd say it's obvious why they're disliked in function names.