Analysis. NET development process named number and person

Source: Internet
Author: User
Keywords Analysis development process annotation can follow
Tags analysis clear code development development process difference framework it is

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, which is discussed below.

Number of nouns

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

Properties: System.Collections.Generic.DictionaryTKey, Keys and count in TValue are good examples. A field is similar to this; a noun in a method name: The getElementById and getElementsByTagName we are familiar with in JS; Local variables: We are more likely to encounter local variables than attributes. 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 liststring 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, look at an example in the. NET framework. In System.Collections.Generic.StackT, there is a contains (T item) method for such code:

if (Thestack.contains (1)) {//do something.}

Read like: If the stack contains 1, 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. First write the code to see:

Thestack.push (3); 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 follow, in the. NET framework, using the third person, whether for type or type members. Other common annotations should also follow this rule.

Related Article

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.