匈牙利命名法是一个命名的变量的类型和/或范围作为变量的命名前缀。比如说呢。
1
2
3
4
5
int value; // non-Hungarian
int nValue; // the n prefix denotes an integer
double width; // non-Hungarian
double dWidth; // the d prefix denotes a double
Hungarian Notation was invented in 1972 by Charles Simonyi, a Microsoft programmer. The original idea of Hungarian Notation was to encode information about the variable’s purpose, which is known as Apps Hungarian. Over time, this focus changed to encoding information about the variable’s type and/or scope, which is known as Systems Hungarian.
There is a lot of controversy over whether Hungarian Notation is useful in modern programming languages and with modern IDEs. We believe the advantages still outweigh the disadvantages, though you will find plenty of programmers who disagree.
One advantage of Hungarian Notation is that the variable type can be determined from it’s name. Many argue that this is an obsolete advantage, because most modern IDEs will tell you a variables type if you mouse-hover over the name. However, consider the following snippet:
1
float applesPerPerson = totalApples / totalPersons;
匈牙利命名法是在1972发明的查尔斯西蒙尼,一个微软程序员。匈牙利符号最初的想法是编码的可变信息的目的,即应用匈牙利。随着时间的推移,这将改变编码的变量的类型和/或范围的信息,这是被称为系统的匈牙利。
有在是否匈牙利符号在现代编程语言和现代IDE是有用的许多争论。我们相信,优点远远大于它的缺点,但你会发现很多程序员谁不同意。
匈牙利表示法的一个优点是,变量的类型可以从它的名字确定。许多人认为,这是一个过时的优势,因为大多数现代IDE如果你将鼠标悬停在名字告诉你某个变量的类型。然而,考虑下面的代码片段: