A code writing standard
[Author: 9pvision Source: --- Hits: 22 Editor: admin] [double click to roll
】
I. General source code format rules 1.1 Development Tools recommended to use Microsoft? Company's Visual InterDev to write ASP code, use Macromedia? Company Dreamweaver to write HTML code, you can also use UltraEdit, Aspedit 2000 and other development tools. 1.2 Indentable space indent spaces refers to two to four spaces at each level. Do not keep TAB characters in the source code, because Tab characters represent different widths with different settings of different users and different resource management tools (print, document, version control, etc.). 1.3 Data Legality Checking All Form Submit Pages, must fill in the project and fill in the Illegal input to fill in the project, and JavaScript is judged in the page in the page. If you must compare with the server-side data, you must judge whether you are correct. example. All submitted information (GET mode and POST mode) must re-perform data legitimacy check in the server side, and filter illegal characters (&; `'/" | *? ~ <> ^ () [] {} $ / N / R), for example, replace "'" replace "' '" (two single quotes) (the work of replacing the string will be uniformly using the common CheckInputString (STR) function); for digital variables, check Whether the input data is all numbers (using isnuMERIC in JavaScript, using isNuMeric). 1.4 Parameter delivery suggests use of a POST method without recommending a GET method; strictly prohibit the use of GET methods, session or other ways; Using the GET method to pass a large number of query strings, especially uncoded Chinese characters, HTTP protocol delivery table single domain is high than query string efficiency, and the page with a large query string will fail on some browsers. Forbidden use of session, cookie to deliver the necessary parameters during the non-session. 1.5 URL contains the header file, the page link, the submitted page, the image used, if referenced, such as "include", "image", etc. Using the absolute path, the path started with a virtual root directory "/" to improve the operation efficiency. For example: 6.4 Dynamic cursor types in ADO using the simplest cursor type and record lock mode: l Dynamic Cursor ( AdopenForwardonly) - Used to view addition, changes, and delete other users, and use to move in all types of mobile non-dependent RecordSet. If the provider supports, you can use the bookmark. l key set cursor (AdoPenkeySet) - its behavior is similar Dynamic cursors, different are prohibited from viewing other users to add records and disable access to other users' deleted records, and the data changes made by other users will still be visible. It always supports bookmarks, thus allowing all types of mobile in RecordSet. L Static ADOPENDYNAMIC - provides a static copy of the record collection to find data or generated reports. It always supports bookmarks, so that all types of mobile in RecordSet. Other users are added, changed or deleted. This is open customer The only cursor type that allows for use when the end (Ado) Recordset object is only the forward cursor (AdoPenStatic), except that it is only allowed to scroll forward in the record. This way, when you need one-way mobile in the Recordset Performance can be improved.
Set the CURSORTYPE attribute before opening Recordset to select the cursor type, or use the Open method to pass the CURSORTYPE parameter. Some providers do not support all cursor types. Check the provider's documentation. If you do not specify a cursor type, ADO will open only the forward cursor by default. Four different cursor types are defined in ADO: LadlockReadonly - default, read-only. Unable to change the data. LADLOCKPESSIMISTIC - conservative record lock (strip). The provider performs the necessary operations to ensure successful editing records, usually using the record of the data source immediately when editing. LADLOCKTIMISTIC - Open Record Locking (strip). The provider uses an open lock to lock the record only when the Update method is called. LadlockBatchOptimistic - open batch update. The batch update mode is used to update now. Setting the LockType property before opening RecordSet Specifies the lock type that the provider should use when the Open is open. Read this property returns the type of lock that is using on the open Recordset object. The LockType property is read / written when Recordset is closed. This property is read-only. The simplest cursor type and record locking method suitable for processing tasks should be used during actual use. For example: only open a static recordset and output: rs.open SQL, CONN, 0, 1 'AdopenForwardonly, ADLOCKREADOONLY Open Record in the record set with text Type: RS.Open SQL, CONN, 1, 1' AdopenkeySet, AdlockReadonly 6.4 SQL String Filter All String Enterlets You must check the function checking, insert, delete or modify a record to the database, ie: character type: "'", "' 'in the submission "Whether using public functions CheckInputString ().) And check if the length of the string is long. Value: Use the isNumeric () to determine if the input is a number. Integer: Use int (), fix (), and Round () intercept its integer value. Date type: Use the isdate () function to determine if the correct date is entered. 6.5 SQL Transaction Execution transactions for database operations generally should be performed using SQL stored procedures. For database operations that need to be performed in the ASP page, all inserts, delete, modify the database must not use the RecordSet object, you must use the Connect object to perform with the SQL statement, the Recordset is only used when the query is executed. All search databases are prohibited from using "Select * from ...", and use "SELECT field 1, field two, field three, ... from ...". 6.6 Closing the ADO object All Connect and RecordSet, etc., the ADO objects such as Connect and RecordSet must be turned off immediately after running, and then release its object (set *** = nothing). 7. Schemes for cookies 7.1 cookies specifies the specific path of the cookies returns the server. In order to make cookies can work with the entire directory of the entire website, Domain domain properties should be set to: "/", and the Domain domain attributes that can be delivered by the browser can be delivered by the browser. To make cookies can work with each sub-site across the website, you should set the Domain domain property to: ". YourDomain.com". This value will be placed in a public file of the site as a constant cookie_domain.
That is: Response.Cookies ("username"). Path = "/" response.cookies ("username"). Domain = Cookie_domain 7.2 Cookies Validity Cookies EXPIRES attribute specifies that the end of the cookies. If you want to create a cookies during a session, you have to fail after the customer ends, you must not set this property. 7.3 Safety of cookies Cookies The internal sensitive information must be encrypted, which is defined in the public key function library. 1.5 URL contains header files, page links, submitted pages, images used, if referenced, such as "include", "Image", etc., must use absolute path, that is, started with virtual root directory "/" Path to improve operational efficiency. For example: Inside a relatively independent module, a relative path can be used to increase portability. However, it is forbidden to use ".." to return to the previous directory, which is forbidden to use the URL similar to "../Images/logo.gif". The relative path is written as follows: Make sure the rear slash (/) is used in the URL pointing to the directory. If you have omitted the rear slash, the browser will send a request to the server, just to tell the server, it is in the request directory. The browser will issue a second request, attach the slash to the URL, only after this, the server can respond to the default document or directory list (if there is no default document and if the directory browsing is available). Additional slash can save the first, useless. To facilitate user reading, you can omit the rear bar in the name. For example, write: http://msdn.microsoft.com/workshop This also applies to Web Site URL on the home page: Use the following: , without using . 1.6 dates , Judgment and display date, be sure to determine the year is 4 bits. Unified definition is the long-term format: XXXX XX month XX Sunday format is: XXXX-XX-XX must use the formatDatetime () function when the ASP output is output. Format, uniformly use the XXXX-XX-XX format when entering the front end input, and uses isdate () in the back end using isdate ().
Second, HTML 2.1 Mark HTML is not sensitive to case, but in order to improve readability, set all signs, attributes, lowercase attribute values, and attribute values must be quoted, such as:
td> 2.7 tag must Use the width and height properties to define the size of the image to speed up the speed of the browser to display the page. For a general non-placeholder picture, Alt property must be used to define its text display. 2.8 Note Use the annotation to declare the start and end of each sub-block area, and the comment statements use English. Such as: head> section of the file to ensure that all functions are loaded and ready before the user interacts with other parts of the page. The action at the page load should also write a function / process, trigger in the Body ONLOAD event. 3.3 String Series Avoid using a string in a cycle statement. It is recommended to use the = operator, ie, use S = "a string" instead of using s = s "a string". 3.4 Event Processor Event Processor is embedded in the HTML tag, which should declare the type of script, such as onMouseOver = "Java script: window.status = 'everyone is" Return True "> 3.5 Note Use" // "to comment The statement within a row, use "/ * ... * /" to comment into a statement. In addition, the script should use HTML Note Tag " script> four, VBScript 4.1 constant / variable, function / process name constant and variable naming should be made to represent its meaning, functional words, the start letter of each word, The remaining letters, the cyclic variables I, J, K can exceed the exception. For frequently used or long items, standard abbreviations are recommended to reason systemize the length of the name. For variables, if the variable is a process level (process, The variables of the sub-process or function during the function should be used in front of the "M_" prefix to represent it is a local variable. For example: m_blncalcinprogress. The local variable should be defined separately in the function or process. Should give the variable to the variable Indicates their data type. Declaring variables in the ASP code according to the way of handling variables (rather than their actual data type).
For example: Variables prefix example bln Boolean blnSuccess cur Currency curAmount dbl Double dblQuantity dat Date and Time datDate flt Float fltRatio lng Long lngMilliseconds int Integer intCounter str String strName arr Array arrUsers () obj named COM Object objPipeline functions and processes to be followed The above basic rules, and with a verb look down 4.2 statement uppercase or the first-letter capital IF, THEN, ELSE, and END IF and other VBScript statements. 4.3 String Connection To maintain consistency and reach a script target with more self-prophet, use the string connecting (&) instead of the plus sign ( ). 4.4 Comments Use annotations to explain the unintegrated or complex code. In-line comments should display two spaces after the corresponding code. The comments starting on the new line should be aligned with the previous row. It is recommended to use single quotes (') instead of the REM key, and add the REM key on the line without code. Comment statements Try to use English. 6. Database & ADO Operation 6.1 Unicode Data Type Database Places in the database to use the Chinese characters to use the Nchar, NVARCHAR, NTEXT type. 6.2 Database Connections All Connection Databases must include header files Connaaaaaaaaaaaaaaaaaaaaa.as for connection data (if different connection files are required, AAAAA represents different modules). Define the connection string using the OLEDB provider to connect the database (not allowed to use the database administrator SA) using the OLEDB provider. This file will not be placed under the site directory to use "include file" way of "Include File". SQL SERVER by using OLEDB, use the following syntax: Provider = SQLOLEDB.1; Password = mypassword; Persist Security Info = True; User ID = myuid; Initial Catalog = mydbname; Data Source = myserver; Connect Timeout = 15 If you want to use data configuration, OLEDB connection using the following syntax: Provider = MSDataShape; Date Provider = SQLOLEDB.1; Password = mypassword; Persist Security Info = True; User ID = myuid; Initial Catalog = mydbname; Data Source = myserver; connect Timeout = 15 6.3 References of ADO attribute constants If you need to use ADO constants, you should add the following code to this file, you can directly access all ADO constants: 6.4 Use the simplest cursor type and record lock mode to define four kinds in ADO Different cursor types: 1 ADOPENFORWARDONLY - Used to view addition, changes, and delete of other users, and use to move in all types of movements that do not depend on bookmarks. If the provider supports, you can use a bookmark. l Key Set Cursor - It is similar to a dynamic cursor. Different is only to view records added by other users, and disable access to other users' deletions, and the data changes made by other users will remain visible. It always supports bookmarks, thus allowing various types of movements in RecordSet. l Static Cursor - Provides a static copy of a record collection to find data or generate a report. It always supports bookmarks, thus allowing various types of movements in RecordSet. The addition, changes, or deletion made by other users will be invisible. This is the only cursor type that allows usage when opening the client (Ador) Recordset object. l Only the forward cursor (AdomentStatic) - its behavior is similar to a dynamic cursor except only to scroll forward in the record. This way, performance can be improved when moving one-way movement in the Recordset. Set the CURSORTYPE attribute before opening Recordset to select the cursor type, or use the Open method to pass the CURSORTYPE parameter. Some providers do not support all cursor types. Check the provider's documentation. If you do not specify a cursor type, ADO will open only the forward cursor by default. Four different cursor types are defined in ADO: LadlockReadonly - default, read-only. Unable to change the data. LADLOCKPESSIMISTIC - conservative record lock (strip). The provider performs the necessary operations to ensure successful editing records, usually using the record of the data source immediately when editing. LADLOCKTIMISTIC - Open Record Locking (strip). The provider uses an open lock to lock the record only when the Update method is called. LadlockBatchOptimistic - open batch update. The batch update mode is used to update now. Setting the LockType property before opening RecordSet Specifies the lock type that the provider should use when the Open is open. Read this property returns the type of lock that is using on the open Recordset object. The LockType property is read / written when Recordset is closed. This property is read-only. The simplest cursor type and record locking method suitable for processing tasks should be used during actual use. For example: only open a static recordset and output: rs.open SQL, CONN, 0, 1 'AdopenForwardonly, ADLOCKREADOONLY Open Record in the record set with text Type: RS.Open SQL, CONN, 1, 1' AdopenkeySet, AdlockReadonly 6.4 SQL String Filter All String Enterlets You must check the function checking, insert, delete or modify a record to the database, ie: character: "'", "' ' "Whether using public functions CheckInputString ().) And check if the length of the string is long. Value: Use the isNumeric () to determine if the input is a number. Integer: Use int (), fix (), and Round () intercept its integer value. Date type: Use the isdate () function to determine if the correct date is entered. 6.5 SQL Transaction Execution transactions for database operations generally should be performed using SQL stored procedures. For database operations that need to be performed in the ASP page, all inserts, delete, modify the database must not use the RecordSet object, you must use the Connect object to perform with the SQL statement, the Recordset is only used when the query is executed. All search databases are prohibited from using "Select * from ...", and use "SELECT field 1, field two, field three, ... from ...". 6.6 Closing the ADO object All Connect and RecordSet, etc., the ADO objects such as Connect and RecordSet must be turned off immediately after running, and then release its object (set *** = nothing). V. ASP program 5.1 Variable declaration must write <% Option Explicit%> in the next line of the program instructions in all ASP pages for variables. Because the local variables are not as slowly as global variables (slower than the defined partial variables). The public file exceptions included. 5.2 Program Description Each program file must indicate the functionality or function of the file, the entry parameters of the program, the parameter description, the author, write a date (including the generation date, final modification date). The following format: <% '**' Comment: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'Input: (must) logon_id-User Name; logon_pd-User Password' (plus) 'Editor: xxxxx 2000-11' Modify: xxxxx 2000-12 '**%> 5.3 Minimization Context Switching For Server Handling Script Performance, it is recommended to minimize HTML and scripts. In a possible case, a few large block scripts should be used instead of multiple dispersed fragments on one page. For example: <% IF a> 1 THEN%> First <% else%> second <% End IF%> It is best to write into the following format: <% if a> 1 Then Response.Write " First " else response.write " Second "END IF%> 5.4 Separation of the script to increase readability (" <% ","%> ") split into code as code Block, instead of writing delimiter in every line. Below code: <% streymail = session ("email")%> <% strfirstname = request ("firstname")%> <% strlastname = request ("lastname")%> should be written as the following format: <% streymail = session "Email" StrfirstName = Request ("firstname") strlastname = request ("Lastname")%> For a separate script row, the delimiter is kept in the same line as a script. For example: <% streymail = session ("email")%> If the script row consists of an equal number and a variable, the equal sign should be part of the delimiter. For example: <% = strsubscrlname%> 5.5 Forbidden use of Session Since the session affects load balancing, the session will no longer use, and uniform use cookie to maintain user status. 5.6 For pages long running time, use the response.flush method Each write operation produces a large system overhead (in IIS, in terms of data from the network through the network), the less the write operation is, the better. Due to its slow start and use the Nagling algorithm (used to mitigate the network plucking condition), TCP / IP is much higher than the efficiency when sending some large data blocks. For a page for long run, the response.flush method must be used. This approach sent all HTMLs converted to the ASP to the browser.
转载请注明原文地址:https://www.9cbs.com/read-54057.html New Post(0)
|