出于非本地化目的的Unicode标识符(函数名称)是否可取? [英] Unicode identifiers (function names) for non-localization purposes advisable?

查看:120
本文介绍了出于非本地化目的的Unicode标识符(函数名称)是否可取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP无论如何都允许变量,函数,类和常量的Unicode标识符.它肯定是针对本地化应用程序的.最好用英语来编写API,但英语是值得商bat的,但是毫无疑问,某些开发设置可能会要求它.

PHP allows Unicode identifiers for variables, functions, classes and constants anyhow. It was certainly intended for localized applications. Wether it's a good idea to code an API in anything but English is debatable, but it's undisputed that some development settings could demand it.

 $Schüssel = new Müsli(T_FRÜCHTE);

但是PHP不仅仅允许\p{L}作为标识符.除了ASCII范围内的字符以外,几乎可以使用任何Unicode字符(例如:是特殊字符或\,因为已经用作支持名称空间的内部技巧.)
无论如何,您可以这样做,我什至认为这对于娱乐项目是可行的:

But PHP allows more than just \p{L} for identifiers. You can use virtually any Unicode character, except those from the ASCII range (e.g. : is special or \ as that's already used as internal hack to support namespaces.)
Anyway, you could do so, and I would even consider that a workable use for fun projects:

 throw new ಠ_ಠ("told you about the disk space before");

除了本地化,娱乐和装饰效果外,建议使用Unicode标识符吗?

But other than localization and amusement and decorative effects, which uses of Unicode identifiers are advisable?

例如,我正在考虑将参数嵌入魔术方法名称中.在我的情况下,我只需要注入数字参数,因此只需使用下划线即可:

For example I'm pondering this for embedding parameters into magic method names. In my case I only need to inject numeric parameters, so would get away with just the underscore:

 $what->substr_0_50->ascii("text");
  // (Let's skip the evilness discussion this time. Not quite sure
  // yet if I really want it, but the conciseness might make sense.)

但是,如果我想嵌入其他文本参数,则需要另一个Unicode字符.现在很难键入,但是如果有一个可以帮助提高可读性并传达含义的话……?

But if I wanted to embed other textual parameters, I would require another unicode character. Now that's harder to type, but if there's one that would aid readability and convey the meaning ... ?

 ->substr✉0✉50->   // doesn't look good

因此,在这种情况下的问题是:哪个符号在虚拟函数名称中作为混合参数的分隔符有意义. -更广泛的meta主题:您知道Unicode标识符的哪些用途,或者您认为还可以吗?

So, the question in this case: Which symbol makes sense as separator for mixed-in parameters in a virtual function name. -- Broader meta topic: Which uses of Unicode identifiers do you know about, or would you consider okayish?

推荐答案

使用哪个符号作为虚拟函数名称中混合参数的分隔符.

Which symbol makes sense as separator for mixed-in parameters in a virtual function name.

\u2639?

除了本地化,娱乐和装饰效果外,建议使用Unicode标识符吗?

But other than localization and amusement and decorative effects, which uses of Unicode identifiers are advisable?

字体支持之后的最大障碍将是使字符可以被键入.在宏或复制/粘贴之外,很难输入unicode字符.将这种情况强加给别人很可能会违反假定在您是谋杀性的精神病患者之后,使用您的代码的人就会知道您的居住地".

The biggest hurdle after font support is going to be making the character one that can be typed. Outside of a macro or copy/paste, unicode characters are not spectacularly easy to enter. Forcing this upon others is very likely going to violate the "assume the people that work with your code after you are murderous psychopaths that know where you live" rule.

我们仅在代码库中的一些注释中使用unicode字符,例如

We use unicode characters in only a few comments in our codebase, like

// Even though this is the end of the file and we should get an implicit exit, 
// if we don't actually expressly exit here, PHP segfaults.
// ♫ Oh, PHP, I love you. ♫

我认为这属于娱乐性和装饰性"类别.或屠杀php内部团队后大刀阔斧".选择一个.

I think that falls into the "amusement and decorative" category. Or the "shoot self in head after slaughtering the php-internals team" category. Pick one.

无论如何,这不是一个好主意,因为这会使您的代码难以修改.

Anyway, this is not a good idea because it's going to make your code hard to modify.

这篇关于出于非本地化目的的Unicode标识符(函数名称)是否可取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆