Download Courage Chibiya BSc Computer Science (Industry)
Transcript
o o o o If your class is just a data store (properties only) then it is probably unnecessary. For public properties use module variables and property Set, Get, Let, not public variables. If a group of input data must be set before calling any methods (general class data, not specific to the method), then consider using module variables instead of public properties, and setting them all in a single datapassing method (DCOM). elipse.Markers.CovarInfo Don’t return results (functions or public properties) as user-defined types (they can’t be accessed by VBScript). Using objects: o Declare object variable as specific class type (not ‘As Object’) wherever possible (early binding). Providing collections: o Create your own specific collection class instead of using the generic Collection class. elipse.Markers ActiveX dll interface: o Where useful to client programmer (and sparingly), provide component ‘global variable’. (Declare as public in standard module, read/write using property Set/Let/Get in GlobalData global multi-use class used for this purpose only.) Database connection: for each database have <DatabaseName>Connect class that just handles database operations (reads, writes etc). Use ADO for any type of database. elipse.elModelConnect o If connection information shouldn’t change during running of client program, receive it in component ‘global variable(s)’. o In Class Initialize: set module variable to open ADODB.Connection, using connection information. o In Class Terminate, set this variable to Nothing. o For database read, sub returns a recordset. o For database write, data supplied as recordset. Code layout: o Use Option Explicit and always declare variable type. Declare private objects together at beginning of proc. Declare global variables together in a single modDeclarations module. o Commenting: use comment blocks at start of object/section etc., and inline comments. Res.asp (elipseWeb_v2), include: At start of each module and proc: what it does. Each variable. Code section for a particular task: at start, what it does. Why something is done in a particular way, if not obvious. All database fields (unless completely obvious) and component type libraries. o Indent to show grouping/nesting (prefer 2 or 3 spaces). o In general, don’t have code lines much longer than screen width (use _). o Use IIf, If…ElseIf, With only where this makes code clearer. Naming conventions: o Never use the same name for different entities. For entities representing the same quantity (e.g. property, module variable representing it, parameter, procedure variable representing it, variables with overlapping scope) use variations on the root name. o Ensure the name conveys sufficient information, and don’t abbreviate unnecessarily, e.g. dtmTransactionDate, not dtmTrnsDte. o strWordStringsLikeThis, not strWord_Strings_Like_This or strwordstringslikethis. o For module variables, use m<SensibleName>, e.g. mTransactionDate. o For global variables, use g<SensibleName>, e.g. gLanguage. o See Appendix for prefixes. 69