C ++中的变量命名约定 [英] Variable Naming Conventions in C++

查看:135
本文介绍了C ++中的变量命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自一个.NET世界,我是新来写C ++。我只是想知道在命名局部变量和结构体成员时,首选的命名约定是什么。

I come from a .NET world and I'm new to writting C++. I'm just wondering what are the preferred naming conventions when it comes to naming local variables and struct members.

例如,我继承的遗留代码有alot

For example, the legacy code that I've inheritted has alot of these:

struct MyStruct
{
   TCHAR           szMyChar[STRING_SIZE];
   bool            bMyBool;
   unsigned long   ulMyLong;
   void*           pMyPointer;
   MyObject**      ppMyObjects;
}



我第一次看到它时不能停止笑pp头)。

Coming from a C# background I was shocked to see the variables with hungarian notation (I couldn't stop laughing at the pp prefix the first time I saw it).

我宁愿用这种方式命名我的变量(虽然我不确定如果大写第一个字母是一个好的约定,我已经看过其他方式(见下面的链接)):

I would much rather name my variables this way instead (although I'm not sure if capitalizing the first letter is a good convention. I've seen other ways (see links below)):

struct MyStruct
{
   TCHAR           MyChar[STRING_SIZE];
   bool            MyBool;
   unsigned long   MyLong;
   void*           MyPointer;
   MyObject**      MyObjects;
}



我的问题:这是(以前的方式) C ++中的变量?

My question: Is this (the former way) still a preferred way to name variables in C++?

参考文献:

http://geosoft.no/development/cppstyle.html

http://www.syntext.com/books/syntext-cpp-conventions.htm

http://ootips.org/hungarian-notation.html

谢谢!

推荐答案

这种匈牙利表示法是没有用的,东西的类型。 ( 正确的种匈牙利表示法是不同的故事。)

That kind of Hungarian Notation is fairly useless, and possibly worse than useless if you have to change the type of something. (The proper kind of Hungarian Notation is a different story.)

我建议你使用你的组。如果你是唯一一个在这个计划上工作的人,你可以用最有意义的方式来命名他们。

I suggest you use whatever your group does. If you're the only person working on the program, name them whatever way makes the most sense to you.

这篇关于C ++中的变量命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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