Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for C# GUI naming conventions? [closed]

GUIs, whether written in WinForms or XAML, seem to have the most widely differing naming conventions between projects I see. For a simple TextBox for a person's name, I've seen various naming conventions:

TextBox tbName      // Hungarian notation TextBox txtName     // Alternative Hungarian TextBox NameTextBox // Not even camelCase TextBox nameTextBox // Field after field with TextBox on the end TextBox TextBoxName // Suggested in an answer... TextBox textBoxName // Suggested in an answer... TextBox uxName      // Suggested in an answer... TextBox name        // Deceptive since you need name.Text to get the real value TextBox textBox1    // Default name, as bad as you can get 

I abide by the StyleCop rules for all my .cs files normally, and see others do so as well, but the GUI tends to break these rules or vary wildly. I haven't seen any Microsoft guidelines that specifically refer to GUI elements instead of just normal variables, or even examples that would apply outside of a console application.

What are the best practices for naming elements in a GUI?

like image 720
Will Eddins Avatar asked Aug 07 '09 19:08

Will Eddins


People also ask

What does best practices mean in programming?

Coding best practices are a set of informal rules that the software development community employs to help improve software quality.


2 Answers

I use the old school hungarian... txt for TextBox, btn for Button, followed by a generalized word, then a more specific word. i.e.:

btnUserEmail 

Have had a lot of people say things like "omg thats so old, VB6 calling!" But in a UI Rich winforms app, I can find and modify things quicker because usually the first thing you know about a control is it's type, then it's category, then get specific. While the newer style naming convention guys are stuck trying to remember what they named that text box.

The original specification for controls is here (archived).

like image 122
Neil N Avatar answered Sep 29 '22 05:09

Neil N


I use:

TextBox nameTextBox; 

Just like I would use:

MailAddress homeAddress; 

The reason for this is that in these cases "TextBox" and "Address" is descriptive of what the object represents, not how it is stored or used. But in another case like storing a person's full name I would use:

string fullName; 

Not:

string fullNameString; 

Because "String" is not descriptive of what the object represents, but only how it is stored.

like image 44
Lee Avatar answered Sep 29 '22 05:09

Lee