views:

262

answers:

7

I've created quite a few user controls to encapsulate GUI functionality used in multiple places in my app. I've noticed I usually have a tendency to describe the function of the control and tack "Control" on the end of the name, but not always. I'd like to standardize the naming and wanted to know if there's a best practice for naming User Controls in .NET?

+1  A: 

Try to stay with something familiar to the user unless you are coding directly for other coders. It is a proven reliability issue not to introduce nomenclature that end-user is not familiar with.

Nicholas Jordan
I'm the only one working on the project, except for another developer that occasionally checks it out and works with a non-UI portion of the project.
jasonh
@jasonh: You may be the only one working on the project *right now*, but that's not an excuse to make things harder on others. Unless you intend to work on this project for the rest of your life, you have to think about your replacement as well (and anyone else who may work on this code 5 or 10 years later, too...).
Daniel Pryden
@Daniel Pryden: I'm aware of that, but since I don't have any other developers I work with now to find out what's familiar to *them*, I'm here to find out what the community thinks I should do. Precisely so that other people down the road can maintain it.
jasonh
@jasonh in reply to Daniel: Okay, and by and large that is a good approach to take but do so for your own work where you pull something from the main body of the code to work on it. My reply was almost verbatim from my risk-management pro, who is degreed with 40+ years field experience. I wrote my whole app with almost no gui, coding it as an afterthought. When I had to show it to my team lead I was careful to write human-readouts that are familiar. What I do is use a RandomStringGenerator for variable names, then name them after I figure out what they do. I now have thirty correctly named...
Nicholas Jordan
A: 

UI elements are the only thing that I still do Hungarian notation for. uctDoesSomething works for me.

This is mostly a preference thing but I find that when I'm selecting a control my thoughts go in the order of "what type of control would it be" and then "what does it do". In that case it makes sense to type out "uct" and let intellisense provide me the alternatives.

George Mauer
+8  A: 

Actually, Control is a pretty good suffix. Consider making a control for Name/Address, you want something in the name that marks it as GUI, instead of Logical.

So I tend to use NameAddressControl.

Henk Holterman
+1  A: 

I also suffix my user controls with "Control"
My typical structure for UI modules would look something like:

DataEntry
-> DataEntryForm
-> DataEntryAddressControl
-> DataEntryNameControl
-> DataEntryAddressItem
-> DataEntryAddressItemCollection
-> DataEntryConfirmationDialog

etc.

works well for our team

Tom Frey
+1  A: 

Like some of the others, we also use the Control suffix for our user controls. (ie ResPayerControl)

RTipton
A: 

There are two methods I've seen used:

  • LoginDateCalendar**Ctl**
  • UCLoginDateCalendar
George Stocker
the OP was asking about Windows Forms user controls, not ASP.NET ;)
Thomas Levesque
Ah, good catch.
George Stocker
A: 

firstNameLA.Text="Name:";

firstNameTI.Text="<Enter your name in this TextInput Control>";

1) lowcaseCamel because controls are default private

2) use suffix instead of prefix for intellisense, etc to pick up by name not type

3) include the type and not simply 'Control', to remind your mind of the real, weireded-out names of all those darn fancy-schmantzy ui comps you gots

Mark