你对成员变量使用什么类型的前缀? [英] What kind of prefix do you use for member variables?

查看:456
本文介绍了你对成员变量使用什么类型的前缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

毫无疑问,理解代码必须给成员变量一个前缀,以便它们可以很容易地与正常变量区分开。

No doubt, it's essential for understanding code to give member variables a prefix so that they can easily be distinguished from "normal" variables.

但是什么样的前缀你使用?

But what kind of prefix do you use?

我一直在使用 m _ 作为前缀的项目,在其他项目中,我们只使用下划线

I have been working on projects where we used m_ as prefix, on other projects we used an underscore only (which I personally don't like, because an underscore only is not demonstrative enough).

在另一个项目中,我们使用了一个长前缀形式,也包含了变量类型。 mul _ 例如是类型为 u m 余烬变量的前缀

On another project we used a long prefix form, that also included the variable type. mul_ for example is the prefix of a member variable of type unsigned long.

现在让我知道你使用什么样的前缀(请给出原因)。

Now let me know what kind of prefix you use (and please give a reason for it).

大多数人似乎在成员变量中没有特殊的前缀。这取决于语言吗?根据我的经验, C ++代码往往使用下划线或 m _ 作为成员变量的前缀。

Most of you seem to code without special prefixes for member variables! Does this depend on the language? From my experience, C++ code tends to use an underscore or m_ as a prefix for member variables. What about other languages?

推荐答案


毫无疑问,理解代码给成员变量

No doubt, it's essential for understanding code to give member variables a prefix so that they can easily be distinguished from "normal" variables.

我对此声明提出异议。如果你有一半体面的语法高亮,这不是最少的一点必要。一个好的IDE可以让你用可读的英语写你的代码,并可以以其他方式向你显示符号的类型和范围。如果插入点在其中一个上,通过突出显示符号的声明和使用,Eclipse会做得很好。

I dispute this claim. It's not the least bit necessary if you have half-decent syntax highlighting. A good IDE can let you write your code in readable English, and can show you the type and scope of a symbol other ways. Eclipse does a good job by highlighting declarations and uses of a symbol when the insertion point is on one of them.

编辑,谢谢slim:一个好的语法荧光笔还允许您使用粗体或斜体文本,或完全更改字体。例如,我喜欢静态东西的斜体。

Edit, thanks slim: A good syntax highlighter like Eclipse will also let you use bold or italic text, or change fonts altogether. For instance, I like italics for static things.

另一个编辑:这样想:变量的类型和范围是辅助信息。它应该是可用的,很容易找到,但不喊你。如果你使用 m _ 或类似 LPCSTR 的前缀,当你只想读取主要信息 - 代码的意图。

Another edit: Think of it this way; the type and scope of a variable are secondary information. It should be available and easy to find out, but not shouted at you. If you use prefixes like m_ or types like LPCSTR, that becomes noise, when you just want to read the primary information – the intent of the code.

第三次编辑:这适用于任何语言。

Third edit: This applies regardless of language.

这篇关于你对成员变量使用什么类型的前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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