473,396 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Naming conventions

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

May 12 '06 #1
3 1333
Chris,
Let me know your opinions.


Since readable code is more important than reducing typing to me, I
don't buy the "shorter name is better" argument. If you use a decent
code editor with code completion, you don't have to type it all in
anyway.

Specifically for the case with Labels used to label other controls, I
rarely have to modify the label control in my code so the label
control's name doesn't really matter. With VS2005 I set GenerateMember
to false. Another approach is to encapsulate the label and the other
labeled control in a UserControl.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 12 '06 #2
You are not alone in this feeling Charles Petzold wrote up some on this here
http://www.charlespetzold.com/blog/2006/05/040939.html

btw: I do the same .. just remember one of the most important concepts of
agile development .. use what works.

Cheers,

Greg Young
MVP - C#
<ca*******************@yahoo.co.uk> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
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

May 12 '06 #3
>Since readable code is more important than reducing typing to me, I
don't buy the "shorter name is better" argument. If you use a decent
code editor with code completion, you don't have to type it all in
anyway.

I would agree completely that readable code is more important than
reducing typing. However, length is not a virtue in and off itself, and
my point is that in this particular case the longer variable names do
nothing to convey the intentions of the author and, if anything,
distract attention from the role the variable plays in a form, and
towards it's type (which is much less important) .

May 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Cristof Falk | last post by:
I wanted to get a feel. The documentation gives naming conventions for public/protected members. Is this truly widely adopted? And what about using the same conventions for private members and...
7
by: cmiddlebrook | last post by:
Hi there, I keep finding myself getting inconsistent with naming conventions for things like member variables, class names etc and I just want to find something that suits me and stick to it. I...
1
by: clintonG | last post by:
Does the use of DTD, XML Schema and similar constructs adopt the use of C# naming conventions? If so how do I make the distinction of how to apply C# conventions with XML elements, attributes and...
4
by: Mark Broadbent | last post by:
stupid question time again to most of you experts but this is something that continually bothers me. I am trying to get into the habit of naming variables and controls in an assembly as per...
3
by: clintonG | last post by:
Does the use of DTD, XML Schema and similar constructs adopt the use of C# naming conventions? If so how do I make the distinction of how to apply C# conventions with XML elements, attributes and...
5
by: rastaman | last post by:
Hi all, I know of the existence of Object Naming Conventions for Visual Basic 6. Now I'm reading some books about VB .NET, but the names used for the objects are button1, picturebox1, etc. I...
4
by: Patrick | last post by:
what are the general naming conventions for vb.net controls. esp txtUserName, lblPassword, btnSubmit What are the prefixes for the controls???? I've tried to search hi and low on the net, but...
9
by: kevininstructor | last post by:
Greetings, I am in the process of creating naming conventions for VB.NET controls i.e. CheckBox -> chkShowThisOnStartup ListBoxt -> lstSomeList What I am looking for other developers...
35
by: Smithers | last post by:
Is it common practise to begin the name of form classes with "frm" (e.g., frmOneForm, frmAnotherForm). Or is that generally considered an outdated convention? If not "frm" what is a common or...
1
by: Philipp Post | last post by:
Marcello, Not a big surprise as naming conventions have a lot to do with personal prefernces. There are a lot of threads in comp.databases and the other database groups. Just do a search for...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.