Vb. NET Coding Specification C # is also applicable

Source: Internet
Author: User

It is important for developers to maintain good coding practices in development. The vb.net coding specification is a coding specification that proves to be able to significantly improve code readability and help with code management and classification. By using this coding criterion, it is possible to avoid long prefixes such as the Hungarian nomenclature, which facilitates the use of memory variables.

650) this.width=650; "src=" http://183.61.143.148/group1/M00/02/4F/tz2PlFQ81SOid0ZnAAA8DOencsE613.jpg "/>

The following describes this coding specification.

I. Naming of type-level units

1, class.

classes declared in class must be named after nouns or noun phrases to reflect the function of the class. such as: Class Indicator

When the class is an attribute (Attribute), End with Attribute, and when the class is an exception (Exception), End with Exception:

Class colorsetexception

Class Causeexceptionattribute

when a class needs only one object instance (global object, such as application, etc.), it must end with class, as

Class Screenclass

Class Systemclass

when a class is used only as a base class for other classes, depending on the situation, end with base: MustInherit class Indicatorbase


if the defined class is a form, then the name must be followed by a suffix form, and if it is a Web form, the suffix page must be added:

Class printform:inherits form * Windows Forms

Class startpage:inherits Page * Web Form

2. Enumerations and Structures

It must also be named after a noun or noun phrase. It is best to embody the characteristics of enumerations or structures, such as:

The enum colorbuttons ends with a complex number, indicating that this is an enumeration

Structure Customerinforecord, ending with a record, shows that this is a structural body

3. Type of delegation

The normal delegate type is named for the noun describing the action to reflect the function of the delegate type instance: Delegate Sub dataseeker (ByVal seekstring as String)

The type of delegation used for event handling must end with EventHandler, such as: Delegate Sub Datachangedeventhandler (ByVal Sender as Object, ByVal e As Datachangedeventargs)

4. Interface

Unlike other types, an interface must be prefixed by I and named with an adjective, highlighting what the class that implements the interface will be capable of: Interface isortable

5. Module

The module is not a type, except that his name must be named after the noun, which must be suffixed with module:

Module Sharedfunctionsmodule

The common feature of all of the above rules is that each word that makes up a name must start with a capital letter, prohibiting the name from being fully capitalized or lowercase.

Ii. naming of methods and properties

1. Methods

The method must be named either as a verb or as a verb phrase, whether it is a function or a subroutine. There is no need to differentiate between functions and subroutines, or to indicate return types.

Sub Open (ByVal commandstring as String)

Function Setcopynumber (ByVal copynumber as Integer)

parameters need to indicate ByVal or ByRef, which is written to make the program side long, but very necessary. If there is no special case, use ByVal. Parameter naming method, refer to "named Method of Variable" later. Methods that require overloading, generally do not write overloads, and write overloaded methods as needed.


2. Properties

In principle, the field is not public, and the property is generally used to access the value of the field. Attributes are named with concise and clear nouns:

Property concentration as single

Property Customer as Customertypes

3. Events

events are special properties that can be used only in the context of an event processing. The principle of naming is usually a word of a verb or verb, which indicates the time of occurrence of an event through tenses:

Event Click as ClickEventHandler

Event colorchanged as Colorchangedeventhangler

Iii. variables and Constants

constants are named for nouns that indicate constant meaning, and generally do not differentiate between constant types: Const defaultconcentration as single = 0.01

in strict code, constants start with c_, such as c_defaultconcentration, but it is best not to use it, which can cause input difficulties.

ordinary types of variables, as long as a meaningful name can not use abbreviations and meaningless names such as A,X1, the following is a good example:

Dim Index as Integer

Dim nextmonthexpenditure as Decimal

Dim CustomerName as String

can not afford too long name, should be as concise as possible, such as the following example:

Dim variableusedtostoresysteminformation as String * error, too complex

Dim systeminformation as String * correct, straightforward

Dim sysInfo as String * error, too simple

special cases can consider a variable of a letter: Dim G as Graphic


for a control, you should indicate the type of the control by directly following the variable with the class name:

Friend WithEvents Nextpagebutton as button * Button

Friend WithEvents Colorchoicerpanel as Panel * Face Edition

Friend WithEvents cardfileopendialog as Fileopendialog * File Open dialog box

Wait, there's no need to specify a prefix for some type of variable, just write the type in the back and try comparing the following code:

btncancel.text = "&cancel"

cancelbutton.text = "&cancel"

Obviously the latter makes it easier for the reader to understand that the type of the variable is a button.

Iv. Labeling

tags are used for goto jump code identification, because Goto is not recommended to use, so the use of the label is also more stringent. The labels must all be uppercase, the middle space is underlined _ instead, and should start with _, for example:

_a_label_example:

the label is defined so that it is sufficiently different from other code elements.

Five, the name space

Usually, a project uses a namespace, usually does not need to use the Namespace statement, but in the project option "Root Namespace", the use of the root namespace can make the code more neat, easy to modify, this is the full advantage of VB. The syntax for namespaces is:

Company name. Product name [. complex number of component names]

such as:

Namespace NINPUTER.VIRTUALSC

e Mentor Network to provide you with more Programming Language Tutorials knowledge, can be logged in to watch.


Vb. NET Coding Specification C # is also applicable

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.