为什么变量名通常以字母“m”开头?
查看Android教程,例如记事本教程,我注意到几乎所有变量都是命名以字母“m”开头。这是什么惯例,它起源于哪里?
Looking at the Android tutorials such as the Notepad tutorial, I noticed that almost all variables are named starting with the letter 'm'. What convention is this, and where does it originate from?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
它代表会员。我个人认为这个约定没有帮助,但它是主观的。
It stands for member. I personally find this convention unhelpful, but it's subjective.
请参阅 贡献者代码风格指南:遵循字段命名约定。 “m”前缀的使用比简单地表示“成员”变量更具体:它用于“非公共、非静态字段名称”。
See Code Style Guidelines for Contributors: Follow Field Naming Conventions. The use of the "m" prefix is more specific that simply denoting a "member" variable: It's for "non-public, non-static field names."
根据 Android 源代码文档:
请注意,这是用于编写 Android 源代码的。对于创建 Android 应用,Google Java 样式指南可能会更有帮助。
According to Android source code documentation:
Note that this is for writing Android source code. For creating Android apps, the Google Java Style Guide may be more helpful.
m在这里表示m成员变量。
它有两个巨大的优点:
The m is here to indicate a member variable.
It has 2 huge advantages:
'm' 表示班级成员。因此,如果您不使用 IDE 来突出显示您的成员,那么您将通过其名称了解它是一个成员。
'm' means member of the class. So, if you don't use IDE to highlight your members, then you will understand that it is a member by its name.
正如已经回答的那样,这个前缀表示变量是成员。
有时,如果您发现某些以“i”或“s”开头的变量,人们会使用其他前缀,它也可能是 匈牙利表示法
As already answered this prefix indcates that a variable is member.
Somtimes people use other prefixes if you discover some variables starting with 'i' or 's' it could also be a variant of the Hungarian Notation
'm' 表示该变量是该类的成员变量...
'm' means the variable is a member variable of the class...
不仅在java中,我在cocos2d+box2d示例中看到了类似的约定,其中一些变量以m_开头,但其他变量则不然,非常令人困惑。
我想区分 C++ box2d 变量和 Obj-C 变量。
not only in java, I've seen similar convention in cocos2d+box2d samples where some of the variables start with m_, but others don't, very confusing.
I guess to differentiate C++ box2d variables from Obj-C variables.