It is very important to maintain a good coding specification in development. The new VB.NET coding specification I use is a coding specification that proves to significantly improve code readability and help code management, classification. This coding specification is used to avoid the use of a long prefix from the Hungarian nomenclature to facilitate memory variables. The following introduction This coding specification is described.
First, named type of unit
1, class.
The class declared by the Class must be named by noun or noun phrase, reflecting the role of classes. Such as:
Class INDICATOR
When class is a characteristic (Attribute), at the end of Attribute, when the class is an exception (Exception), the EXCEPTION ends:
Class ColorseTexception
Class CauseexceptionAttribute
When categories only have an object instance (global object, such as Application et al), must end with Class, such as
Class ScreenClass
Class SystemClass
When the class is only used as the base class of other classes, according to the situation, the end is ended with the BASE:
Mustinherit Class IndicatorBase
If the defined class is a form, then the following must be added to the suffix form, if it is a web form, you must add a suffix Page:
Class Printform: Inherits Form '* Windows Form
Class StartPage: Inherits Page '* Web Form
2, enumeration and structure
Also must be named in noun or noun phrases. It is best to reflect the characteristics of enumeration or structure, such as:
Enum colorbuttons' ends with complex, indicating this is an enumeration
Structure customer customerinforecord 'ends with RECORD, indicating this structure
3, delegation type
Ordinary delegation type named the name of the action to reflect the function of delegate type:
Delegate Sub Dataseeker (Byval Seekstring AS String)
The delegation type used for event processing must end with EventHandler, such as:
Delegate Sub DatachangeDeventHandler (Byval E AS DatachangeDeventArgs)
4, interface
Unlike other types, the interface must be used as a prefix, and is named with adjective, how to highlight the class that implements the interface.
Interface isortable
5, module
The module is not type. His name must be named Module in addition to the name of the noun.
Module SharedFunctionsModule
The common feature of all of the above rules is that the words of each composition name must be the beginning of the uppercase, and the names of complete uppercase or lowercase are prohibited.
Second, method and attribute naming
1, method
Whether it is a function or a subroutine, the method must be named by verb or verb phrases. There is no need to distinguish functions and subroutines, and there is no need to indicate the return type.
Sub Open (byval commandstring as string)
Function setCopyNumber (Byval CopyNumber AS Integer)
The parameters need to indicate that byval is still byref, this is written to make the program edge long, but it is necessary. If there is no special situation, use ByVal. Named method of the parameter, refer to the "Name Method for Variable". The method that needs to be overloaded, generally does not write overloads, and write overloads as needed. 2, attribute
In principle, the field (field) cannot be disclosed, to access the value of the field, generally used attributes. The property is naming with a simple and clear noun:
Property Concentration As Single
Property Customer As Customertypes
3, event
The event is special attribute and can only be used in the event handling context. The principle of naming is generally the words of verbs or verbs, and through the time indicating the time of the incident:
Event Click AS CLICKEVENTHANDLER
Event ColorChanged As ColorChangeDeventhangler
Third, variables and constants
The constant is named indicating the meaning of the meaning of the constant meaning, generally different types of constants:
Const defaultconcentration as sales = 0.01
In the strict requirements, the constant starts with C_, such as c_defaultconcentration, but it is best not to use it, it will bring difficulty.
Ordinary type variables, as long as nammetry with meaningful names, can not use the referreditter ornamental name, such as A, X1, etc., the following example is given below:
DIM INDEX AS INTEGER
Dim nextmonthexpenditure as decimal
DIM Customername As String
You can't get too long, you should try as simple as possible, as follows:
Dim variableusedtostoresysteminformation as string '* error, too complicated
DIM systemInformation as string '* is correct, simple and clear
DIM SYSINFO AS STRING '* Error, too simple
Special circumstances can consider a letter of a variable:
DIM G AS Graphic
For controls, you should indicate the type of control, the method is to be classified directly behind the variable:
Friend Withevents NextPageButton as button '* button
Friend Withevents ColorchoicrPanel As Panel '*
Friend WitHevents CardFileOpendialog as fileopendialog '* file open dialog
Wait, there is no need to specify a prefix of a type of variable, just write the type it will be written later, try comparison the following code:
BTNCANCEL.TEXT = "& ca ZANCEL"
CancelButton.text = "& ca Zancel"
Obviously the latter makes the reader understand the type of variables.
Four, label
The label is the code identifier used for GOTO jumps, because GOT is not recommended, the label is used is more demanding. The label must be on top of the upper capital, the middle space is used underline _ instead, and should be _ beginning, such as:
_A_label_example:
This definition tag is to distinguish from other code elements.
V. Name Space
Typically, a project uses a name space, usually does not need to use the Namespace statement, but specified in the "root namespace" of the project option, using the root namespace can make the code more neat, easy to modify, this is the advantage of VB full. The syntax of the name space is: company name. Product name [. Component name]
Such as:
Namespace ninputer.virtualscreen
Namespace ninputer.cardeditor.customeControls
Just starting a name space, the name is definitely not a good idea, be sure to comply with the above provisions.
Sixth, note
There are many rules of the annotation. Here is only one point: normal comments start with '*, alone' only uses the code for temporary unused
'* This is an ordinary note
'* This code is added correctly after debugging
'IF usehighspeed (g) = true kil ....
This makes it easy to use the code annotation tool to control the use of code.
The above has been briefly introduced to the VB.Net code specification I use, and this code specification is also suitable for C #. For your reference only.