Which naming convention do you use and why?
I like to use employeeNameTextBox, because:
As I read it, an article linked to in the article mentioned in the question (namely, Names of Resources) does use the control type at the end, in FileMenu
(and ArgumentException
though it's not a control).
My personal opinion is that this is also more readable, as it's the employee name text box and hence should be named the employeeNameTextBox
, just like the words "File menu" are read in that order. (Though I substitute "Edit" for "TextBox" for brevity — I should probably kick that habit to use control names consistently with the environment name for them.)
I propose a third option: uiEmployeName. Reasons:
Ideas:
Avoid encodings/abbreviations.
The name should stand out from similar names in the same scope. Make the unique-most part the left-most part. I suspect you have several text boxes, but only one is the employee name.
Avoid needless context. Are all the names on this page about employees? Is it an "employee" page? Then EmployeeName is redundant. NameBox or NameControl should be plenty.
Avoid needless context: do you have names that are not controls? If so, "Box", or "Control" is useful, otherwise not so much.
Disclosure: I am the "ottinger" from "ottingers naming rules", which also evolved to be chapter 2 of "Clean Code". See short form at http://agileinaflash.blogspot.com/2009/02/meaningful-names.html
You should do whatever it is 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 guidelines (such as not using Hungarian notation), but it is more important that you are consistent and clear with your naming convention, whatever it is, than you follow some rules found on the Internet.