CString变量名前缀 [英] CString variable name prefix

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

问题描述



CString变量名的接受(假设有...)前缀是什么?为澄清,我已经看到以下其他数据类型:

  int iIndex; // integer 
int * pIndex; // pointer
bool fFlag; // bool flag

还有无数的人。

解决方案

如果这是一个非问题,或者有任何你想要的答案,请随时与我们联系。 >前缀,例如那些是滥用匈牙利语符号的概念。



HN的想法是,变量前缀有描述其使用的代码。例如,保存某事的计数的变量将前缀 cnt ;保存索引的变量将前缀为 inx 。保存标志的变量将前缀为 f 。保存数字的变量(不是计数或索引或其他常见变量)将以 n 为前缀。



然而,很快,人们就懒惰了,(很大程度上是由于最后一个例子),前缀开始只是数据类型的一个指示。这在C中有一些用处,其中变量的声明必须在函数的顶部,可能与使用它的位置有一定距离。 (特别是当代码是在一个简单的文本编辑器中编写的)



但是,最终,我们有更多的类型安全语言和更好的IDE,和蔑视。


Easy question for you vets out there:

What is the accepted (assuming there is one...) prefix for a CString variable name? For clarification, I've seen the following for other data types:

int  iIndex;  //integer
int* pIndex;  //pointer
bool fFlag;   //bool flag

And there are countless others. Please feel free to let me know if this is really a non-question or something with a "Whatever you want" answer.

解决方案

Prefixes such as those are an abuse of the concept of Hungarian Notation.

The idea of HN is that a variable is prefixed with a code describing its use. e.g., a variable holding the count of something would be prefixed cnt; a variable holding an index would be prefixed inx. A variable holding a flag would be prefixed f. A variable holding a number (that wasn't a count or an index or something else common) would be prefixed n.

However, soon people got lazy, (and largely due to that last example) and the prefixes started to be just an indication of the data type. This has some use in C, where the declaration of a variable had to be at the top of the function, potentially some distance from where it is used. (especially when code was written in a simple text editor)

But, eventually, we got more type safe languages, and better IDEs, so the faux-Hungarian Notation because unnecessary and scorned.

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

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