textBoxEmployeeName vs employeeNameTextBox

后端 未结 16 957
死守一世寂寞
死守一世寂寞 2020-12-16 00:11

Which naming convention do you use and why?

I like to use employeeNameTextBox, because:

  • It seems more natural from an English language perspective.
相关标签:
16条回答
  • 2020-12-16 01:05

    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.)

    0 讨论(0)
  • 2020-12-16 01:08

    I propose a third option: uiEmployeName. Reasons:

    1. It's not Hungarian. Both of the notations you mention are just flavors of Hungarian.
    2. If you change an employee name text box over to a listbox you don't need to rename your variables.
    3. Everything is grouped nicely in the intellisense without involving the type of the object.
    4. The name of the object closely follows its function. It is a user-facing object that gets the employee name.
    0 讨论(0)
  • 2020-12-16 01:08

    Ideas:

    1. Avoid encodings/abbreviations.

    2. 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.

    3. 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.

    4. 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

    0 讨论(0)
  • 2020-12-16 01:10

    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.

    0 讨论(0)
提交回复
热议问题