Introduction: Kent Beck once said, "I am just a more payable programmer" "
Preface:
1. The importance of design specifications: reasons N, not in multiling
2. Applicability of this article: VB.NET development ASP.NET development
Comment code's goal:
1. Narrate the role of clearing the code (what to do, not how to do)
2. Clearly explaining the ideology and logic to express
3. Indicate the important turning point in the code
4. Reduce code readers run in their brain analog code
Note: Note that you should explain the purpose of the code, don't narrate how to complete the target's structure, you have to do so, not how to do it.
Use of special characters identify the comment: '$' @ at the beginning of the line representing commented code written by different people
I. Descriptive document specification
Write the file header ending at each .vb, indicating the function of the entire file)
1.1 in '--------------------------------- ------------------------ Start and end
1.2 File Name: File Name
1.3 Author Version Version: Date and Completion Date:
1.4 DESCRIPTION: For details on the main function of this program file, the interface, output value, value range, meaning, and parameters of other modules or functions, etc., sequential, independent or dependence, etc.
1.5 Others: Description of other content
1.6 Function List: Major function list, each record should include a function name and function brief description
1.7 History: Modify the list of history, each modified record should include the date of modification, modify the author and modification
1. Date:
AUTHOR:
Modification:
2.. . . . . . . . . . . .
II. Specification for process annotation
2.1 in '--------------------------------- ------------------------ Start and end
2.2 DESCRIPTION: Function Description
2.3 Parameters: Parameter Description
2.4 Calls: Functions or procedures called by this process
2.5 Called By: Call the function list of this process
2.6 Table Accessed: Acuted tables (this item only involves the database operation)
2.7 Table Updated: Modified table (this item only involves the database operation)
III. Note Specification for Function
3.1 Function: Function Name
3.2 Description: Description of Function, Performance, etc.
3.3 Calls: Functions called by this function
3.4 Called By: Call the function list of this function
3.5 Table Accessed: Acuted tables (this item only involves the database operation)
3.6 Table Updated: Modified Table (This item only involves the database operation)
3.7 Parameters: Enter parameter description, including each parameter
Use, value, and parameters.
3.8 RETURN: Description of the function return value
Fourth. Naming specification
4.1 Control Parts Named Specification
4.1.1
Ordinary control
Name prefix example
ADROTATOR ADRT ADRTTOPAD
Button BTN BTNSUBMIT
Calendar Cal Calmeetingdates
Checkbox Chk Chkblue
CheckBoxlist Chkl Chkfavcolors
CompareValidator Valc Valcvalidage
CustomValidator Valx Valxdbcheck
DataGrid DGRD DGRDTITLES
DataList DLST DLSTTTLTLES
DRIOPDOWNLIST DROP DROP
Hyperlink Link Lnkdetails
Image IMG IMGAUNTTTY
ImageButton IBTN IBTNSUBMIT
Label LBL LBLRESULTS
LinkButton LBTN
Listbox LST
Panel PNL
Radiobutton Rad
RadopButtonList Radl
Rangevalidator Valg
RegularExpression Vale
Repeater RPT
RequiredFieldValidator VALR
Table TBL
TableCell TBLC
TableRow TBLR
Textbox txt
Validationsummary Vals
XML XMLC
4.1.2
a
DO.NET control naming
Connction ConnorthWind (CON Database Name)
Command cmd cmdreturnproducts
Parameter PARM PARMPRODUCTID
DataAdapter Dad DadproductsDataReader DTR DTRPRODUCTS
DataSet Dst DstnorthWind
DataTable DTBL DTBLPRPDUCTS
DataRow Drow Drowrow98
Datacolumn DCOL DCOLPRODUCTID
DataRelation Drel DrelmasterDetaril
DataView DVW DVWFILTEREDPRODUCTS
4.1.3
Target named by variable:
Ø Clear the use of variables
Ø Make the data type and visible range of each variable clearly
Ø Make the process in the code easy to understand
Ø Make the program easy to debug
Ø Make the storage and processing of the variable more effective
4.2 Variables and constant naming specifications
Array Arr ArrshoppingList
Boolean BLN BLNISPOSPOSPOSPOSPOSPOSPOSPOSPOSTBACK
Byte Byt bytpixelvalue
Char chr chrdelimiter
DateTime DTM DTMStartDate
Decimal Dec DecaverageHeight
Double DBL DBLSIZEOFUNIVERSE
Interger Int Introwcounter
Long LNG
Object obj
Short SHR
Single SNG
String Str
4.3 Function Process Naming Specification
4.3.1
Unified word order :: verb name
4.3.2
The first letter of the word is capitalized and the name should be able to express their use (or meaning).
4.3.3
The parameter needs to indicate whether BYVAL is or byref (parameter is passed by value or by address delivery) 4.4 class naming specification
I. Class declared in Class, must be named by nouns or noun phrases, reflecting the role of classes
II. When the class is a feature (Attribute), at the end of Attribute, when the class is an exception, the EXCEPTION ends:
Class ColorseTexception
Class CauseexceptionAttribute
Iii. It must be at the end of Class, if the class is only an object instance (global object, such as Application et al.)
Class ScreenClass
Class SystemClass
Iv. When class is only used as a base class for other classes, depending on the situation, the end of the base is end:
Mustinherit Class IndicatorBase
v. 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
Vi. Module is not type, his name must be added to Module in addition to noun
: Module SharedFunctionsModule
V. Design specification:
5.1 Objects Received Variables to Variables or Controls Need to judge whether the object is a Nothing Example:
IF not customer is nothing then
Else
'Missing customer data is handled by the account and logon pages
END IF
5.2 Instead of replacing meaningless values with meaningful constants when using the DataSet object:
Correct: with customer.tables (CustomerData.customers_table) .rows (0)
TXTEMAIL.TEXT = CSTR (.ITMERDATA.EMAIL_FIELD))
End with
WrM: with customer.tables (0) .rows (0)
TXTEMAIL.TEXT = CSTR (.Item (0))
TXTEMAIL.TEXT = CSTR (.item ("email"))
End with
5.3 Removal of extra spaces when taking a text box value:
Tmpassword = countrytextbox.text.trim ()
5.4 Two-story nesting or above If else endiff considers the use of SELECT CASE statement:
Wrong: if DataGrid1.Items (i) .Cells (4) .text = "0" THEN
Elseif DataGrid1.Items (i) .Cells (4) .text = "1" THEN
Elseif DataGrid1.items (i) .cells (4) .text = "2" THEN
DataGrid1.items (i) .cells (4) .text = "Trained"
END IF
Correct: Select Case DataGrid1.Items (i) .Cells (4) .Text
Case "
1"
Case "2"
Case "
3 "
Case Else
End SELECT
5.5 INSERT statement (convenient table expansion)
Correct format: INSERT [INTO] TableName (FieldName1, FieldName2), Values (Value1, Value2)
Error format: insert [inTo] Tablename Values (Value1, Value2)
5.6 All operations must be shortcuts, support keyboard operations
5.7 Use the do ... loop loop instead of while ... End while loop
5.8 Do not use Boolean expressions with Ture or false
Incorrect usage: iSemptyRecordset = (rs.eof = Ture) and (rst.eof = tuue)
Correct usage: iSemptyRecordset = rs.eof and rst.eof
IF not (blnvalidtemplate). Then
5.9 Even if the expression does not require parentheses, add parentheses in order to logic clearly
5.10 use unified and direct clear way to call the process
Call the SUB process To use the Call keyword (different from the function called without the return value)
Incorrect usage PerformWordMerge (StrMergefile)
Correct usage: Call PerformWordMerge (StrMergefile)
5.11 Even if the function without the return value is also always accepted the return value of the function
5.12 Return Function Value Using Return
Incorrect usage: priavire function myfunction () as boolean
MyFunction = true
End Sub
Correct usage: priavire function myfunction () as boolean
Return True
End Sub
5.13 Programming rules for constants
All constants plus prefix c_ and range indicators
For example: const c_interestrate = 6 during the process
Module (private) private const mc_intersrate = 6
Global: public const gc_intersrate = 5
5.14 Never use the connection of the string, use the & symbol
5.15 Packet associated with blank line
In IF ... ..Then, SELECT CASE Structure Front and then inserts blank lines before and after each cycle
After declaring a set of variables, insert a blank line after performing the statement group of the same task, two blank lines are inserted between the procedures.
5.16 Define a clear range for each process
Incorrect usage: SUB DISP
Lay ConfiirmationMessage
End Sub
Correct usage: Public Sub DISP
Lay ConfiirmationMessage
End Sub