. NET official coding methods and naming rules

Source: Internet
Author: User
Tags coding standards min

Coding method

The coding approach incorporates many aspects of software development. Although they usually have no effect on the functionality of the application, they are useful for improving the understanding of the source code. This takes into account all forms of source code, including programming, scripting, tagging, and query languages.

The coding method defined here is not recommended to form a set of fixed coding standards. Instead, they are intended as guidelines for developing coding standards for specific software projects.

The coding method is divided into three parts:

Named

Comments

Format

Named

Naming schemes are the most powerful help for understanding the logical flow of an application. The name should say "what" rather than "how." You can preserve the abstraction layer of simplified complexity by avoiding the name of the public base implementation that will change. For example, you can use Getnextstudent () instead of getnextarrayelement ().

The naming principle is that the difficulty of choosing the correct name may indicate the need to further analyze or define the purpose of the item. Make the name long enough to be meaningful and short enough to avoid being verbose. Unique names are programmed to be used only to separate areas. Strong names are meant to help people read, so it makes sense to provide names that people can understand. However, make sure that the name you select conforms to the rules and standards of the applicable language.

The following are the recommended naming methods.

Routines

Avoid difficult names that can easily be interpreted subjectively, such as analyzethis () for routines, or xxK8 for variables. Such a name can cause ambiguity, not just abstraction.

In an object-oriented language, it is superfluous to include a class name in the name of a class property, such as Book.booktitle. Instead, you should use Book.title.

Use the verb-noun method to name a routine that performs a specific action on a given object, such as Calculateinvoicetotal ().

In languages that allow function overloading, all overloads should perform similar functions. For languages that do not allow function overloading, establish a naming standard that makes similar functions happen.

Variable

Append the calculation qualifier (AVG, Sum, Min, Max, Index) to the end of the variable name as appropriate.

Use complementary pairs in variable names, such as Min/max, Begin/end, and Open/close.

Since most names are constructed by connecting several words, use a mixed-case format to simplify their reading. In addition, to help differentiate between variables and routines, use Pascal casing for routine names (Calculateinvoicetotal), where the first letter of each word is capitalized. For variable names, use camel case handling (documentFormatType), where the first letter of each word is capitalized except for the first word.

Boolean variable names should contain is, which means yes/no or true/false values, such as Fileisfound.

When naming a state variable, avoid using terms such as Flag. A state variable differs from a Boolean variable where it can have more than two possible values. Instead of using Documentflag, you use a more descriptive name, such as documentFormatType.

A meaningful name is still used even for variables that may be short-lived in a few lines of code. Use a single letter variable name, such as I or J, for a short loop index only.

Do not use literal digits or literal strings, such as for i = 1 to 7. Instead, you use named constants, such as for i = 1 to Num_days_in_week in order to maintain and understand.

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.