现在的位置: 首页 > 综合 > 正文

vb.net程序设计规范(2)

2013年10月03日 ⁄ 综合 ⁄ 共 4388字 ⁄ 字号 评论关闭

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 account 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)

          方便表的扩充

         56 所有的操作要有快捷键,支持键盘操作

        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

        模块中(privateprivate 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 都是自己在实际编程中的经验教训不在列举了,希望大家也能总结一下作为自己的规范

抱歉!评论已关闭.