C
catharticmomentusenet
I apologise because I am aware there have already been a large number
of posts on this topic, but I couldn't find one making precisely the
points I wanted to make
I am a senior developer at a company that looking at adopting coding
standards for .NET. Many of the standards available on the net are
based around Microsoft's guidelines, and recommend that, since .NET is
strongly typed, hungarian notation is unnecessary and should be
avoided.
To a large extent I agree with this - as long as variable names are
chosen properly then I find concerns over .NET variable types to be
very rare - definitely not worth the decrease in readability that
hungarian creates.
However, in one respect I differ from the guidelines - naming of Gui
controls. It is quite common to have several controls that are
conceptually related on a form, and for them all to have similar names.
I find hungarian notation to be a very useful shorthand in this case.
For example, consider a label "Please enter your name" and an
associated text box. I have seen code that would declare these as:
Label userNameLabel;
TextBox userNameTextBox;
This seems to me to be unnecessarily wordy compared to the hungarian
alternative:
Label lblUserName;
Textbox txtUserName;
When the shorter notation is regularly employed and everyone is used to
it, then the hungarian variant is more readable - since often the
operations being performed are the most important part of the code, and
excessively long variable names can cause these operations to become
obscured.
In many cases, the type of a variable is often either irrelevant or
obvious from context. For example if text is assigned from a user name
control then the important thing is that a user name has been entered,
not the type of the control. Hence it doesn't make sense to me for the
type to take up so much of the variable's name. The only reason to
include the type at all is to distinguish the two closely related
controls. If anyone has a better method for distinguishing user
controls with similar purposes then please post it.
Let me know your opinions.
Thanks,
Chris Williamson
of posts on this topic, but I couldn't find one making precisely the
points I wanted to make
I am a senior developer at a company that looking at adopting coding
standards for .NET. Many of the standards available on the net are
based around Microsoft's guidelines, and recommend that, since .NET is
strongly typed, hungarian notation is unnecessary and should be
avoided.
To a large extent I agree with this - as long as variable names are
chosen properly then I find concerns over .NET variable types to be
very rare - definitely not worth the decrease in readability that
hungarian creates.
However, in one respect I differ from the guidelines - naming of Gui
controls. It is quite common to have several controls that are
conceptually related on a form, and for them all to have similar names.
I find hungarian notation to be a very useful shorthand in this case.
For example, consider a label "Please enter your name" and an
associated text box. I have seen code that would declare these as:
Label userNameLabel;
TextBox userNameTextBox;
This seems to me to be unnecessarily wordy compared to the hungarian
alternative:
Label lblUserName;
Textbox txtUserName;
When the shorter notation is regularly employed and everyone is used to
it, then the hungarian variant is more readable - since often the
operations being performed are the most important part of the code, and
excessively long variable names can cause these operations to become
obscured.
In many cases, the type of a variable is often either irrelevant or
obvious from context. For example if text is assigned from a user name
control then the important thing is that a user name has been entered,
not the type of the control. Hence it doesn't make sense to me for the
type to take up so much of the variable's name. The only reason to
include the type at all is to distinguish the two closely related
controls. If anyone has a better method for distinguishing user
controls with similar purposes then please post it.
Let me know your opinions.
Thanks,
Chris Williamson