引言:Kent Beck 曾經說過“我只是個更注重的程序規范的程序員而已”
發表于:2007-06-30來源:作者:點擊數:
標簽:
4.2 變量和常數命名規范 array arr arrShoppingList Boolean bln blnIsPostBack Byte byt bytpixelValue Char chr chrDelimiter DateTime dtm dtmStartDate Decimal dec decAverageHeight Double dbl dblSizeOfUniverse Interger int intRowCounter Long lng
4.2 變量和常數命名規范
array arr arrShoppingList
Boolean bln blnIsPostBack
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 函數過程命名規范
4.3.1統一的單詞順序::動詞+名次
4.3.2單詞的首個字母大寫并且名稱應該能表達出它們的用途(或者說是意義)。
4.3.3 參數需要指明ByVal還是ByRef(參數是按值傳遞還是按地址傳遞)
4.4 類命名規范
i. 以Class聲明的類,都必須以名詞或名詞短語命名,體現類的作用
ii. 當類是一個特性(Attribute)時,以Attribute結尾,當類是一個異常(Exception)時,以Exception結尾:
Class ColorSetException
Class CauseExceptionAttribute
iii. 當類只需有一個對象實例(全局對象,比如Application等),必須以Class結尾,如
Class ScreenClass
Class SystemClass
iv. 當類只用于作為其他類的基類,根據情況,以Base結尾:
MustInherit Class IndicatorBase
v. 如果定義的類是一個窗體,那么名字的后面必須加后綴Form,如果是Web窗體,必須加后綴Page:
Class PrintForm : Inherits Form @#*
Windows窗體
Class StartPage : Inherits Page @#* Web窗體
vi. 模塊不是類型,他的名稱除了必須以名詞命名外,必須加以后綴Module
:Module SharedFunctionsModule
五 設計規范:
5.1對象取值賦給變量或者控件時需要判斷對象是否為nothing 例:
If not Customer is Nothing Then
Else
@# Missing customer data is handled by the a
clearcase/" target="_blank" >ccount and logon pages
End If
5.2 在使用dataset 對象時 用有意義的常量代替無意義的值 例:
正確的: With Customer.Tables(CustomerData.CUSTOMERS_TABLE).Rows(0)
TxtEmail.Text = CStr(.Item(CustomerData.EMAIL_FIELD))
End With
錯誤的:With Customer.Tables(0).Rows(0)
TxtEmail.Text = CStr(.Item(0))
TxtEmail.Text = CStr(.Item(“Email”))
End With
5.3 取文本框數值的時候需要去除多余的空格例:
tmpPassword = CountryTextBox.Text.Trim()
5.4 兩層嵌套以上的 if else end if 考慮使用 select case 語句 例:
錯誤的: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 = "已
培訓"
End If
正確的: select Case DataGrid1.Items(i).Cells(4).Text
case “1”
case “2”
case “3”
case Else
end select
5.5 Insert 語句的正確格式:Insert [into] TableName (FieldName1,FieldName2),values( value1,value2)
錯誤的格式: Insert [into] TableName Values (value1, value2)
方便表的擴充
5.6 所有的操作要有快捷鍵,支持鍵盤操作
5.7 用do……loop 循環代替 while…… end while 循環
5.8不要用boolean表達式與ture 或false比較
不正確的用法:isEmptyRecordset= (rs.eof= ture) and( rst.eof=tuue)
正確的用法: isEmptyRecordset= rs.eof and rst.eof
if not (blnValidTemplate). Then
5.9即使表達式不需要圓括號,為了邏輯清晰也要加上圓括號
5.10 使用統一和直接明了的方式調用過程
調用sub過程要使用call 關鍵字(區別于沒有返回值的函數調用)
不正確的用法 performWordMerge(strMergeFile)
正確的用法:call performWordMerge(strMergeFile)
5.11 即使沒有返回值的函數也要始終接受函數的返回值
5.12使用return 返回函數值
不正確地用法:priavire function myFunction () as Boolean
myFunction =true
end sub
正確地用法:priavire function myFunction () as Boolean
return true
end sub
5.13常量的編程規則
所有的常量前面加上前綴C_和范圍指示符
例如:過程中 const c_InterestRate=6
模塊中(private)private Const mc_IntersRate=6
全局: public Const gc_intersRate=5
5.14決不要用+做字符串的連接符,要使用&符號
5.15用空白行把相關的語句分組
在 if …..then ,select case 結構 每個循環體 的前后插入空白行
在聲明一組變量后,執行同一任務的語句組之后插入空白行
過程之間插入兩個空白行
5.16給每個過程定義一個明確的范圍
不正確地用法:sub disp;lay confiirmationmessage
end sub
正確地用法:public sub disp;lay confiirmationmessage
end sub
…………………….還有N條 都是自己在實際編程中的經驗教訓不在列舉了,希望大家也能總結一下作為自己的規范
原文轉自:http://www.kjueaiud.com