Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hungarian notation in C# [duplicate]

Before using C#, C++ was my primary programming language. And the Hungarian notation is deep in my heart.

I did some small projects in C# without reading a C# book or other guidelines on the language. In those small c# projects I used something like

private string m_strExePath; 

Until I read something from SO that said:

Do not use Hungarian notation.

So why? Am I the only person that has m_strExePath or m_iNumber in my C# code?

like image 699
Jason Avatar asked Apr 20 '09 13:04

Jason


People also ask

What is Hungarian notation in C language?

Hungarian notation is an identifier naming convention in computer programming, in which the name of a variable or function indicates its intention or kind, and in some dialects its type.

What is Hungarian notation give an 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.

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 notation and camel notation?

Camel Notation- In this naming convention first character of all words, except the first word are Upper Case and other characters are lower case. Hungarian Notation - In this naming convention the variable name starts with group of small letter which indicate data type.


1 Answers

Joel Spolsky has a really good article on this topic. The quick summary is that there's two types of Hungarian notation that are used in practice.

The first is "Systems Hungarian" where you specify the variable type using a prefix. Things like "str" for string. This is nearly useless information, especially since modern IDEs will tell you the type anyway.

The second is "Apps Hungarian" where you specify the purpose of the variable with a prefix. The most common example of this is using "m_" to indicate member variables. This can be extremely useful when done correctly.

My recommendation would be to avoid "Systems Hungarian" like the plague but definitely use "Apps Hungarian" where it makes sense to. I suggest reading Joel's article. It's a bit long winded but explains it much better than I could.

The most interesting part of this article is that the original inventor of Hungarian notation, Charles Simonyi, created "Apps Hungarian" but his paper was horribly misinterpreted and the abomination of "Systems Hungarian" was created as a result.

like image 102
17 of 26 Avatar answered Sep 21 '22 12:09

17 of 26