Hungarian notation is an identifier naming convention in which the name of a variable or function is prefixed by its type or intended use. For example:

  • lAccountNum: l says the variable is a long integer.
  • szName: sz says the name is a zero-terminated string.

But today, many people are against its use. Why?

History

Let’s look back in history. Hungarian notation found its first major use with the BCPL programming language, which has a backronym Before C Programming Language. From that it’s easy to see this is an ancient language. Yes, it is an ancient language designed in 1966 and it is a typeless language where everything is a word. In that situation, Hungarian notation can help with naked-eye type-checking.

However, many years have passed since then…

And here’s what the latest Linux kernel documentation (as of 2016) says:

Encoding the type of a function into the name (so-called Hungarian notation) is brain damaged - the compiler knows the types anyway and can check those, and it only confuses the programmer.

Now it’s obvious why its use is discouraged now.

Two Types of Hungarian Notation

However, we should note that there are actually two types of Hungarian notation:

  • Systems Hungarian notation: The prefix encodes physical data type.

  • Apps Hungarian notation: The prefix encodes logical data type.

Because of compiler technology advancement, systems Hungarian notation is no longer recommended due to type-checking redundancy. But today’s compilers still cannot check logical data types (semantics) very well. Therefore, using apps Hungarian notation may still be helpful depending on the situation. As a rule of thumb, Hungarian notation is good if and only if it describes semantics that are not available otherwise.