VB.NET coding specification

xiaoxiao2021-03-19  220

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. 1. Name 1 of type grade units, class. The class declared by the Class must be named by noun or noun phrase, reflecting the role of classes. If Class Indicator When the class is a feature (Attribute), the Attribute ends, when the class is an exception (Exception), the EXCETIONTETEXCEPTION CAUSEEXCETTETEXCEPTION CAUSEEXCEPTIONATTRIBUTE When the class only has an object instance (global object, such as Application Wait, you must end with Class, such as class screenclass class systemclass, when class is only used as a base class as other classes, depending on the situation, with the base end: Mustinherit Class IndicatorBase If the defined class is a form, then the name must be added later Suffix Form, if it is a web form, you must add a suffix Page: Class Printform: Inherits Form '* Windows Form StartPage: Inherits Page' * Web Form 2, enumeration and structure must also be named in terms of noun or noun. It is best to reflect the characteristics of enumeration or structure, such as: Enum colorbuttons 'ending with multiplexes, indicating that this is an enumeration structure customer customerinforecord' ending with RECORD, indicating that this is a structural 3, delegated type ordinary delegation type to describe the action noun named to reflect delegate instance of type function: delegate Sub DataSeeker (ByVal SeekString as String) delegate type for handling the event, must end the EventHandler, such as: delegate Sub DataChangedEventHandler (ByVal Sender as Object, ByVal e as DataChangedEventArgs) 4 The interface is different from other types. The interface must be used as a prefix, named adjective, highlighting how to implement the interface, how to achieve interface: Interface isortable 5, module module is not type, his name In addition to naming, must be named A suffix module: Module SharedFunctionsModule The common feature of all of the above rules is that the words of each component must be uppercase, and the names of complete uppercase or lowercase are prohibited. Second, the method and attribute naming 1, the method must be named by verb or verb phrases, whether it is a function or subroutine. 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 "parameter requires that Byval is still byref, this is written to make the program side length, 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. In principle, field (field) is unusable, to access the value of the field, generally use attributes. Named attributes with simple and clear nouns: Property Concentration As Single Property Customer As Customertypes 3, event events are special attributes that can only be used in event processing context. The principle of naming is generally the words of verbs or verbs. Through the time indicating the time of the event: Event Click AS ClickeVentrand ColorChange AS ColorChangeDeventhangler 3, variables, and constant constants to name the constant meaning, generally different types of constants: const DEFAULTCONCENTRATION AS SINGLE = 0.01 In strict requirements, the constant is started with C_, such as c_defaultconcentration, but it is best not to use it, it will bring difficulty. Ordinary type variables, as long as naming with meaningful names, can not use the referredit of the referreditteris and meaning, such as A, X1, etc. Get a big name, should be as simple as possible, as follows: Dim VariableUsedToSystemInformation As String '* Error, too complex DIM SystemInformation As String' * correct, simple Dim SysInfo AS String '* error, too simple special case can be considered a letter variable: Dim g As Graphic for controls, type should indicate the control, is to be the class name directly after the variable: Friend WithEvents NextPageButton As button '* button Friend WithEvents ColorChoicerPanel As Panel' * Panel Friend WithEvents CardFileOpenDialog As FileOpenDialog '* File open dialog, etc., there is no need to specify a prefix of a type of variable, just write the type behind, try to compare the following code: btncel.text = "& cancel" carative "CancelButton.Text =" & cancel " More to make the reader understand the type of variable is a button.

转载请注明原文地址:https://www.9cbs.com/read-130271.html

New Post(0)