tags:

views:

42

answers:

1

Hello,

What is the best and recommended practice regarding capitalization for naming controls in, for example, WinForms?

StyleCop says that instances of classes should start with a lower case letter. I respect this convention in my code.

In previous languages that I have used, for example VB6, I have been used to name my UI controls dropped on the form starting with an upper case character, like ZipCodeTextBox.

But a control dropped on a form actually is little more than an instance of a class, so it would make sense for the StyleCop rule to apply, so, zipCodeTextBox. Most of the naming conventions document do not go further and do not specifically cover the UI controls.

I have seen code using the two naming conventions in various projects, books, and blogs posts, so I'm curious what is the generally recommended practice on this and why?

Thanks.

+4  A: 

That's covered in the MSDN documentation here: http://msdn.microsoft.com/en-us/library/ms229002.aspx

There is, of course, room for flexibility, but in my own humble opinion, I think you're better off sticking with these guidelines, as they will be recognized by most .Net developers.

However, for controls, we veer from the standards in our shop... We allow hungarian notation on form controls. It's not standard, but it's a lot easier to know you're looking for a textbox, and start typing "txt" and have intellisense bring up the list of textboxes on your form. We realize it's not standard, and it's not as nice looking in code, but it speeds productivity enough to make it a fair trade-off.

David Stratton
Of course, VS2010 intellisense makes it much easier to avoid Hungarian notation and retain meaningful names.
Jeff Yates
+1 for that link. Thanks! And I agree with Jeff, VS2010 intellisense is awesome.
Ecyrb
+1 for admitting the the 'incorrect' usage of hungarian notation is a speedup and productivity booster. Joel has done a great disservice to all who listen and have stopped this practice - now they are searching around for their properties amid 100 default properties for forms, etc. SPEED and EASY pay $$$, correctness for correctness sake - e.g. naming conventions that are less usefull - COST $$. have fun...
FastAl
Resharper also can do substring-based auto-completion. So, if I type TextBox it will enumerate me all my TextBoxes even though I used it as a suffix. For some, and it is starting to convince me, it reduces the point of using hungarian notation for controls.
Kharlos Dominguez