Should I use it or not?
My intuition says, “No.” But various coding styles where I work suggest using it.
However, I’m drawn towards it for web form controls, but only ever so slightly, and it was a long time ago that I formed that opinion. Since then my feelings on variable-naming have annealed.
Using an IDE such as Visual Studio and programming in C# which is strongly-typed, there is no need to signify the type of a variable in its name. The IDE ensures that only the correct operations are performed on the variable for its type.
There is also the inherent contradiction in coding styles that use Hungarian notation for types in the .Net framework System namespace, but not for other classes in other namespaces.
In a weakly-typed language, using Hungarian notation is a great help in reducing errors because there is no IDE to stop you adding a variable representing a Boolean value in one scenario to a variable representing a series of digits in another scenario.
Though I’m also drawn to using Hungarian notation for the same fundamental data but represented in different data types, such as when a number is represented as a String and an Int32 in two different variables. I can live with this as a contradiction because it is a rule designed to seek clarity with the basic non-Hungarian standard.
So, my feelings on Hungarian notation are:
In weakly-typed languages, use Hungarian notation.
In strongly-typed languages, do not use Hungarian notation, except when the same fundamental entity is being represented by variables of different types.
Now I just have to convince others...
No comments:
Post a Comment