Analysis. NET development process named number and person

Source: Internet
Author: User

We all understand the importance of naming, and if we are constantly concerned about naming, we need to consider the names of verbs and nouns, in particular the number of person and noun of the verb.

In the guideline of the. NET framework, there is a special chapter that discusses naming conventions, including capitalization, word selection, and so on, but not in terms of person and quantity, and here's a couple of things to discuss.

Number of nouns

First look at the quantity. In order to improve readability, the number of singular and plural nouns has a significant difference in semantics and needs to be carefully considered. Like what:

Properties: System.collections.generic.dictionary<tkey, Keys and count in tvalue> are good examples. The field is similar to this; the noun in the method name: We are familiar with getElementById and getElementsByTagName in JS;

Local variables: We are more likely to encounter local variables than properties. For example, using a variable to represent a person's name, you can use string name; If it is more than one person's name, you can use list<string> names.

In general, the semantics of singular expressions are? (0 or 1); The semantics of complex expressions are * (0, 1, or more). The number of nouns is easy to understand, and the relevant rules are easy to follow.

The person of the verb

Next consider the verb's person. In objects that need to be considered for naming, including namespaces, types, and various types of members, only the method is a verb, semantically representing an action. About it, take a look at an example in the. NET framework. In System.collections.generic.stack<t>, there is a contains (T item) method for such code:

 
  
  
  1. if (Thestack.contains (1))
  2. {
  3. Do something.
  4. }

It reads like this: If the stack contains 1, it's more fluent. Are all methods to be named like this? No. The other two methods clear () and push (T item) are not so, this place is very confusing. Let's write code first.

 
  
  
  1. Thestack.push (3);
  2. Thestack.clear ();

Try to read as a sentence as above: the stack push 3; The stack clear, grammatically incorrect, and seems to be the third person. I'm not sure why, but I can only try to explain. After examining multiple collection types and other types, it is found that all places using the third person are predicate functions, in addition to the CONTAINS (T item) and Directory.Exists (string path), do not know if this is the naming convention?

Also consider notes

To some extent, annotations are also a kind of code. One is the XML document annotation, which we can also follow, in the. NET framework, using the third person, whether for type or type members. Other common annotations should also follow this rule.

Original link: http://www.cnblogs.com/anderslly/archive/2011/01/26/name-conventions.html

"Edit Recommendation"



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.