• 0

.NET Controls naming convention


Question

Hello, I am new to .NET programming. There is a set of naming convention in Java, for example, methodName for method name, CONTNT for constants. I want to know if there is also a set of naming conventions for .NET controls, such as textbox, labels, data grid...etc?

Thank you very much! :)

Link to comment
https://www.neowin.net/forum/topic/785788-net-controls-naming-convention/
Share on other sites

Recommended Posts

  • 0

One reason for the hungarian notiation is that we humans are visual atuned. We recognize patterns quite easily. Having a three char prefix allows developers to on sight know the object type.

I use a dirivative of the hungarian that uses a single char prefix for variables, two char prefix for database objects and three char prefix for objects (UI and other) This allows me to very quicky understand what is going on without having to run the code (to see var types) or look at the declaration.

Yes, there are some issues with this such as changing the variable type and then insuring that the prefix is changed everywhere. (That can suck) but I do not believe that it's such large bagage. I am currently working on a JavaScript site that was written with no patterns what-so-ever. It's a horrible way to work.

There is single good answer (drat) so what I often tell beginners and jr devs is to find a pattern and a logic that works for them. Don't simply use a pattern because others say it's good. (Which seems the reason for this post in the first place) and learn to adapt to new patterns and logic as they are put in front of you.

  • 0

Here's a good article about the merits of Hungarian notation and addresses some of the concerns that people have over it.

The use of this sort of notation has been the subject of debate for many years, so people's positions on this tend to be rather dug in. But I should note that a lot of the backlash against Hungarian notation originated from how it was initially used at Microsoft. For example, a lot of the earlier Windows APIs would use "dwSize" to denote the size of an object (systems Hungarian). But all that it told you was that it was a 32-bit uint, which, in most cases, was useless information. And worse, if the type changes, then the name becomes obsolete. lParam and wParam used to make sense in Win16, but wParam became a misnomer when it was promoted to 32 bits in Win32, and both became a misnomer when they were both promoted to 64 bits for Win64. Whereas the newer APIs will use cbSize (count, in bytes, of the size). The cb prefix (an apps Hungarian prefix) is extremely useful (especially in situations where you dealing with raw memory (using bytes) and strings (using characters, which is 2 bytes each in UCS-2)). "f" for "flag" is also useful, and differentiating between "I" and "C" for interface and class is essential for reading COM without getting a headache.

So a lot of it depends on how you use the notation, and just like comments, you can use it in a useful way or in a dumb way. I personally think that had the Windows API used the notation in a more "apps"-oriented manner that there would not have been this historical distaste for it and that there would be more consensus today over its usefulness. The larger and more complex the project (in which you will have other people who are not familiar with the code reading it and in which you are more likely to not remember the details of the code when you return to it), the greater the payoff to Hungarian.

Edited by kliu0x52
  • 0
  The_Decryptor said:
lblLabelName, txtTextBoxName, etc.

I picked it up when using VB6 and now I can't stop using that format with anything I do.

I also use Hungarian Notation. An especially unintuitive method is using names like FirstName or FirstNameTextBox. If I know there's a textbox for the first name, my first guess is going to be txtFirstName, but intellisense will kick in after txt listing all textboxes etc.

  • 0
  GraphiteCube said:
Thanks for replies, but... Have Microsoft published a set of recommendations/ suggestions/ standards on naming convention? Or at least a well-known/ well-accepted standard?

FxCop flags things like so:

public properties/methods/fields: Standard case (e.g.: IsEnabled, DoWorkQueue())

private fields: lower case beginning (e.g.: internalCount)

hungarian notation: No. (e.g. NameTextBox, not txtNameBox)

There's an entire MSDN library section about it here.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.