TextBoxEmployeeName vs employeeNameTextBox

What naming convention do you use and why?

I like to use employeeNameTextBox because:

  • This seems more natural in terms of English.
  • I find it easier to search with Intellisense.
  • The convention is similar to the convention used for events (MouseClickEvent, MouseClickEventHandler) and dependency properties (VisiblityProperty).

Note. I use the full name, not the abbreviation (for example, "tb"), because it complies with the MS naming conventions that are said to avoid using abbreviations.

http://msdn.microsoft.com/en-us/library/ms229045.aspx

+11
naming-conventions winforms wpf hungarian-notation
Jan 13 '09 at 18:23
source share
16 answers

The only reason to use the control type in the first name (textBoxEmployeeName) to simplify grouping with Intellisense (all text field controls will be displayed together). Other than this, there is no benefit from using this method. I find the second method (employeeNameTextBox) more readable and prefer this method personally, but many people will still have the type of control first, as it has been done for a long time.

+7
Jan 13 '09 at 18:40
source share

I (almost) always use [controltype] [descriptive name]. I want to know what type of control I encounter when I look at the code, and if I DO NOT remember the name, intellisense can help me.

Just using a descriptive name (EmplyeeName) doesn't work for me. What type of control? Is this a label, text box, or combo box? Or a string? Or a file? It is important enough that the type of control or variable is always part of it.

+4
Jan 13 '09 at 19:48
source share

Naming your variables is so important. Contrasting representations seem to fit the short end of the stick. Here are my thoughts:

  • Never put getters and setters for actual business values ​​in your opinion. Do not do this:

    public Name EmployeeName { get; set; } 
  • To get or set EmployeeName, your status code must explicitly call the method. Do it like this because it predicts that the state is not saved in the view, but can be obtained or transferred to the view:

     public void SetEmployeeName(Name employeeName); public Name GetEmployeeName(); 
  • Hungarian notation is stupid. This was useful in languages ​​<= VB6, as they used late binding of variable types. You had to protect yourself because type mismatches were runtime errors, not compile time. Use only txtEmployeeName if you will also use strEmployeeName and intEmployeeNumber .

  • If the template name prefix is ​​not consistent with your naming convention, do not do this for the type of control (which represents the template). If you would not create commandNameFormatting (instead of nameFormattingComamnd ), do not create textBoxEmployeeName .

  • You probably need some kind of suffix, as EmployeeName does not adequately describe the purpose of the variable. The purpose of the EmployeeName text field is to get input. You can name it EmployeeNameTextBox , if it is convenient for you, but it is better to name it EmployeNameInput . This has an added bonus, if you have a label, it is clear that EmployeeNamePrompt (or EmployeeNameLabel ) does not match the text box. Without any descriptive suffix, you have no good way to differentiate.

+3
Jan 14 '09 at 13:20
source share

I usually try to keep the element type short, followed by a distinctive label. I found that it quickly reports the type and purpose of the element:

 txtEmployeeName; lblEmployeeName; 
+2
Jan 13 '09 at 19:54
source share

I suggest the third option: uiEmployeName. Causes:

  • This is not Hungarian. Both designations that you mentioned are simply flavors of the Hungarian language.
  • If you change the text box of the employee name to a list, you do not need to rename the variables.
  • Everything is well grouped in intellisense without involving an object type.
  • The name of the object closely follows its function. This is an object addressed to a user who receives the name of an employee.
+2
Mar 02
source share

Why not the name EmployeeName? Seriously, how does the type of control, as part of the name, when already provided by your IDE, help provide simple code maintenance? Consider Ottenter Rules for Variable and Naming Classes

TO

+1
Jan 13 '09 at 18:48
source share

As I read, the article related to the article mentioned in the question (namely Resource Names ) uses the control at the end of FileMenu (and ArgumentException , although this is not a control).

My personal opinion is that it is also more readable, as this is a text field for the name of the employee and therefore should be named employeeNameTextBox , as well as the words "File Menu" are counted in that order. (Although I replace “Edit” for “TextBox” for short and mdash, I should probably use this habit to use control names in series with the environment name for them.)

+1
Jan 14 '09 at 0:11
source share

A MUST READ is the XAML Guidelines released by Jaime:

Also read here

+1
Jan 14 '09 at 2:00
source share

WPF-specific answer: no name at all.

Why? Because if you are developing WPF, you should not name your controls. If so, you are doing something wrong.

WinForms required the controls to be named because the data binding was so weak. WPF solves all this: the control itself can determine its data and behavior, so there is no need to call it.

+1
Mar 02 '10 at 17:49
source share

I would go with [controlType] [DomainTerm] , which in this case is textBoxEmployeeName . The reason is that when coding the C # code behind you, you care more about user interface elements, rather than domain-specific conditions. UI (View) lateral coding, we need to quickly identify / recognize the type of control, which is a bit more important than the domain specific name in the viewing side, and since we read from left to right , this naming convention matters. I usually use txtEmployeeName or cmpEmployeeType, but a textBox instead of txt is preferred according to MS recommendations.

0
Jan 13 '09 at 18:46
source share

I do not recommend Hungarian notation in any form. textBoxEmployeeName is a form of Hungarian notation. Therefore, I support the use of employeeNameTextBox.

Personally, I don’t even want to use the word TextBox, because this is not what is important for the variable. It is important that "Employee" and "Name". Not only adding the word TextBox blocks you to a particular type, but it also makes it much harder to change that type, because you need to change the name to normalize your code and make it correct. Say for some reason that you started it as a TextBox, but later you received a request to change it to DropDownList or some other type, now you need to update all your code and JavaScript to force DropDownList instead of TextBox.

It’s much easier to forget how to type the names of variables and just name them. You have intellisense and compile-time checking for some reason why not use it.

0
Jan 13 '09 at 20:00
source share

I used both txtEmployeeName and employeeNameTextbox. Like many of these posts, this is useful for grouping. One group by type of control (txtEmployeeName, txtManagerName), and the other can group different related controls together (employeeNameTextbox, employeePhoneTextbox, managerNameTextBox, managerPhoneTextbox). In many cases, I find that a later version is more useful when coding.

0
Jan 14 '09 at 13:48
source share

You must do everything that makes your code readable and self-documenting. Following hard and fast rules is always a mistake, because they almost never cover all aspects of what needs to be done. There is nothing wrong with having recommendations (for example, do not use Hungarian notation), but it’s more important that you are unanimous and clear in your naming convention, no matter what it is, than to follow some rules found in the Internet.

0
Jan 14 '09 at 14:06
source share

Ideas:

  • Avoid encodings / abbreviations.

  • The name should stand out from similar names in the same field. Make a unique bulk to the left. I suspect you have several text fields, but only one employee name.

  • Avoid unnecessary context. Are all the names on this page about employees? Is this the employee page? then EmployeeName is redundant. NameBox or NameControl should be a lot.

  • Avoid unnecessary context: do you have names that are not controls? If so, the Box or Control is useful, otherwise not so much.

Disclosure: I am the ottinger of the ottingers naming rules, which also became chapter 2 of Clean Code. See Short Form at http://agileinaflash.blogspot.com/2009/02/meaningful-names.html

0
Mar 02 '10 at 17:18
source share

I think it's best to follow the Microsoft Object Naming Convention for naming your controls in both C # and Visual Basic.

0
Aug 19 '15 at 8:59
source share

In VB, I really enjoy going with [ControlName] _ [ControlType]. I can’t remember how I started to do this, but I suppose this seems like a logical order. It also simplifies coding, because code sentences are grouped by control description, not by type of control.

I call control the same way in C #, except that I follow the C # preference for camelCase: [controlName] _ [controlType].

I also use my own shortcuts for control types, although they are not vague.

Examples:

VB: Save_Btn and NewFile_MItem (menu item)

C #: Save_Btn and NewFile_MItem

This works for me, but of course every programmer has his own style.

0
Dec 02 '16 at 3:45
source share



All Articles