Sunday, July 25, 2010 Coding Standards

In the development of good coding standard is very important. I have adopted the new coding standards is a significant improvement has been shown to code readability, and helps the code management, classification and coding specifications. Using this coding standard, to avoid such as Hungarian notation prefix length brought prosperity, easy to use memory variables. Here are this numbering.

First, type the name level units

1, class

Class statement to the class, must be a noun or noun phrase naming, reflecting the role of the class. Such as:

Class Indicator

When the class is a feature (Attribute), the order Attribute end, when the class is an exception (Exception) when to end Exception:

Class ColorSetException

Class CauseExceptionAttribute

When only one object class instance (the global object, such as Application, etc.), must be Class ends, such as

Class ScreenClass

Class SystemClass

When the class is only used as a base class for other classes, depending on the circumstances, to Base at the end:

MustInherit Class IndicatorBase

If the definition of the class is a form, then the name must be followed by additional suffix Form, if a Web form, you must add the suffix Page:

Class PrintForm: Inherits Form''* Windows Forms

Class StartPage: Inherits Page''* Web Forms

2, enumeration and structure

The same noun or noun phrase must be named. Best reflects the characteristics of enumeration or structure, such as:

Enum ColorButtons''in the plural ending, that this is an enumerated

Structure CustomerInfoRecord''to Record at the end, that this is a structure

3, designated type

Ordinary delegate type named after the term to describe the action to reflect the delegated functions of the type instance:

Delegate Sub DataSeeker (ByVal SeekString As String)

For event handling delegate type EventHandler must end, such as:

Delegate Sub DataChangedEventHandler (ByVal Sender As Object, ByVal e As DataChangedEventArgs)

4, the interface

With other types, interfaces must be prefixed by the I, and named with adjectives, the most prominent class implement the interface will have the capabilities to:

Interface ISortable

5, module

Module is not the type name in addition to his name must be the term, the must be the suffix Module:

Module SharedFunctionsModule

The common feature of all the rules, each component name must be capitalized at the beginning of words, prohibit entirely uppercase or lowercase name.

Second, the naming of methods and properties

1, methods

Whether the function or subroutine, method must be named by the verb or verb phrase. No need to distinguish between functions and subroutines, and need not specify the return type.

Sub Open (ByVal CommandString As String)

Function SetCopyNumber (ByVal CopyNumber As Integer)

Parameters necessary to specify ByVal or ByRef, procedures that make up the side of writing, but very necessary. If there are no special circumstances, use the ByVal. Parameter naming, refer to the back of "variable naming." Need to override the method, generally do not write Overloads, according to need to write overloaded methods.

2, attribute

In principle, the field (Field) is not open to the public to visit the field's value, general use properties. Attribute to simple clear terms naming:

Property Concentration As Single

Property Customer As CustomerTypes

3, event

Event is a special property, only in the event handling context. The general principle of naming is a verb or verb word, by the time state that the time the incident:

Event Click As ClickEventHandler

Event ColorChanged As ColorChangedEventHangler

Third, variables and constants

Constant to indicate that the constant sense of the term named, generally do not distinguish between the types of constants:

Const DefaultConcentration As Single = 0.01

In the strict requirements of the code, constants with c_ beginning, such as c_DefaultConcentration, but best not to use it, it will have input difficulties.

Common type of variable, with a meaningful name as long as you can not use short and meaningless name such as A, x1, etc., are given below a good example:

Dim Index As Integer

Dim NextMonthExpenditure As Decimal

Dim CustomerName As String

The name can not play too long and should be concise, as the following example:

Dim VariableUsedToStoreSystemInformation As String''* error, too complicated

Dim SystemInformation As String''* correct, clear and simple

Dim sysInfo As String''* error, too simple

Special circumstances can be considered a letter variables:

Dim g As Graphic

For the controls, should indicate the type of control, is directly behind them in the variable class name:

Friend WithEvents NextPageButton As Button''* button

Friend WithEvents ColorChoicerPanel As Panel''* panel

Friend WithEvents CardFileOpenDialog As FileOpenDialog''* file open dialog

So, no need to provide some type of a variable prefix, just the type of writing in the back on the line and try to contrast the following code:

btnCancel.Text = "& Cancel"

CancelButton.Text = "& Cancel"

Obviously the latter can make the reader understand the type of a variable is a button.

4, labeling

Tag is used to identify the code jump Goto, Goto is not recommended because, so the use of tabs are relatively harsh. Tags must be all caps, the middle of the space with an underscore _ to replace, and should be _ at the beginning, for example:


Such a custom label and other code elements to the full difference.

5, name space

Typically, a project that one name space, usually do not use Namespace statement, Er Shi Zai project options of the "Root Namespace" Zhong Zhi Ding, using root name space can make Daimagengjia tidy, Rongyixiugai, that 1:00 is full of advantages of VB . Namespace syntax is:

Company name. Product Name [. Component name plural]

Such as:

Namespace Ninputer.VirtualScreen

Namespace Ninputer.CardEditor.CustomeControls

Random name from a name space is not a good idea, we must comply with the requirements.

6, Notes

Note numerous rules, only mentioned one thing here: the normal''* Note to the beginning of a separate''only without the code being used to annotate

''* This is a general comment

''* This code is correct in adding debugging

''If UseHighSpeed (g) = True Then ....

This can be easily controlled with code annotation tool for the use of the code.

Has introduced more than a simple I am using code specification, the code specification also applies to C #. Only for your reference.

Recommended links:

More than to see PR value of the exchange of links Matters need attention

Avi to mkv

My MSN is NOT the same as your

dvd Ripper

Terminal And TELNET Clients introduction

how To convert .mp4 to .avi

Waste cartridge up to 5 times the false profit Canon ink cartridge recycling difficult

Icons Directory

Teaching And Training Tools Catalogs

New Timers And Time Synch

CSS examples: horizontal style input boxes

Charles Zhang: Sohu Is Looking For The Next Opponent

Free download mp4 to 3gp

Win XP to crash when you become extremely smart!

China Machinery Industry Federation leading research Beijing Petroleum Machinery Factory

Michael Dell Back The First Three Fire Burning

Antitrust who first stumbled HOM

No comments:

Post a Comment