Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do people use the Hungarian Naming Conventions in the real world? [closed]

Is it worth learning the convention or is it a bane to readability and maintainability?

like image 506
Brock D Avatar asked Aug 07 '08 22:08

Brock D


People also ask

Is Hungarian notation still used?

The Hungarian notation is redundant when type-checking is done by the compiler. Compilers for languages providing type-checking ensure the usage of a variable is consistent with its type automatically; checks by eye are redundant and subject to human error.

What is Hungarian naming?

Hungarian people's names are "reversed" compared to most other European names; the family name precedes the given name. For example, the anglicized name "Charles Simonyi" in Hungarian was originally "Simonyi Károly". In the same way, the type name precedes the "given name" in Hungarian notation.

Are naming conventions important?

Naming conventions make sure users know how to name digital assets so that filenames or titles are consistent and contain all the right information. They help you store and organise your files. Without them, your asset library can become chaotic and make it much harder to find images when you need them.

What is Hungarian notation example?

In Systems Hungarian notation, the prefix represents the actual data type of the object. For instance, if the object named Greeting were a zero-terminated string, its Systems Hungarian name might be szGreeting. Or, if the object YesOrNo were a boolean variable, its Systems Hungarian name would be bYesOrNo.


1 Answers

Considering that most people that use Hungarian Notation is following the misunderstood version of it, I'd say it's pretty pointless.

If you want to use the original definition of it, it might make more sense, but other than that it is mostly syntactic sugar.

If you read the Wikipedia article on the subject, you'll find two conflicting notations, Systems Hungarian Notation and Apps Hungarian Notation.

The original, good, definition is the Apps Hungarian Notation, but most people use the Systems Hungarian Notation.

As an example of the two, consider prefixing variables with l for length, a for area and v for volume.

With such notation, the following expression makes sense:

int vBox = aBottom * lVerticalSide; 

but this doesn't:

int aBottom = lSide1; 

If you're mixing the prefixes, they're to be considered part of the equation, and volume = area * length is fine for a box, but copying a length value into an area variable should raise some red flags.

Unfortunately, the other notation is less useful, where people prefix the variable names with the type of the value, like this:

int iLength; int iVolume; int iArea; 

some people use n for number, or i for integer, f for float, s for string etc.

The original prefix was meant to be used to spot problems in equations, but has somehow devolved into making the code slightly easier to read since you don't have to go look for the variable declaration. With todays smart editors where you can simply hover over any variable to find the full type, and not just an abbreviation for it, this type of hungarian notation has lost a lot of its meaning.

But, you should make up your own mind. All I can say is that I don't use either.


Edit Just to add a short notice, while I don't use Hungarian Notation, I do use a prefix, and it's the underscore. I prefix all private fields of classes with a _ and otherwise spell their names as I would a property, titlecase with the first letter uppercase.

like image 109
Lasse V. Karlsen Avatar answered Oct 12 '22 09:10

Lasse V. Karlsen