Tutorials to .com

Tutorials to .com » Dotnet » Oop » C # written norms

C # written norms

Print View , by: iSee ,Total views: 19 ,Word Count: 2065 ,Date: Tue, 21 Apr 2009 Time: 8:19 PM

One, named for understanding the logic of the application flow, named the most influential program is a help. Name should indicate "what" rather than "how." By avoiding the use of the basis for the realization of an open (they will change) the name, can be retained to simplify the complexity of the abstraction layer. For example, you can use GetNextStudent (), rather than GetNextArrayElement ().
Naming principles are:
Select the correct name of the difficulties might indicate the need for further analysis or definition of the purpose. To make the name long enough to have a certain significance, and short enough to avoid lengthy. The only name in the program only used to distinguish between the various. The name of the performance of power is to help people to read;, therefore, provide the name of one can understand is meaningful. However, please be sure to select the name of the language consistent with applicable rules and standards.
The following points are recommended nomenclature.
1, methods, properties, variables easily be subjective norms to avoid the difficult to explain the name, such as aspects of AnalyzeThis (), or property name xxK8. Such a name would result in ambiguity.
In object-oriented languages, the name of the property in the category included in the class name is redundant, such as Book.BookTitle. But should be used Book.Title.
The use of the verb - the term approach to the naming of a given object routines to perform specific operations, such as CalculateInvoiceTotal ().
Allowed to function in the language of heavy-duty, all heavy-duty should be to implement a similar function.
As long as the appropriate variable name in the end or the beginning of the calculation plus qualifiers (Avg, Sum, Min, Max, Index).
The use of variable names in each other right, such as min / max, begin / end and the open / close.
Given that most names are constructed by connecting a number of words, use mixed-case format to simplify their reading. In addition, in order to help distinguish between variables and routines, please use the name of Pascal routines to deal with case (CalculateInvoiceTotal), each of which the first letter of the word is capitalized. For variable names, use camel case to deal with (documentFormatType), which in addition to the first word of each word outside the first letter is capitalized.
Boolean variable names should contain Is, This means that the Yes / No or True / False value, such as fileIsFound.
State variables in the naming, to avoid the use of terms such as the Flag. Boolean variables is different from the state variables is that it can have more than two possible values. Instead of using documentFlag, but use a more descriptive name, such as documentFormatType. (The only reference)
Even if that might appear in only a few lines of code in a very short survival time variable, still using the name meaningful. Index only for the short-cycle single-letter variable names, such as i or j.
Possible, try not to use the original meaning of the original meaning of number or string, such as For i = 1 To 7. But the use of named constants, such as For i = 1 To NUM_DAYS_IN_WEEK in order to facilitate the maintenance and understanding.






Second, the code written norms
Formatted so that the logical structure of the code is obvious. Take the time to ensure that the source code to the same format logical way, which you and your development team, as well as future maintenance of the source code of other developers have a lot of help.
The following points are recommended methods to format.
Indent the size of the establishment of standards (such as four spaces), and consistent use of this standard. Alignment with the provisions of the code section of the indentation.
Release the source code in the hard copy version, as well as use a specific font size (New Song, small V).
In parentheses on the location of the vertical alignment alignment brackets left and right brackets, such as:
for (i = 0; i <100; i + +)
(
;
)
Tilt can also use the style that appears in brackets at the end of the left and right brackets appears the first line, such as:
for (i = 0; i <100; i + +) (
;
)
No matter which style to choose, please use the entire source code for that style.
Logical structure along the line indent code. Not indent, code will be difficult to understand, such as:
if (expression)
(
/ /
/ / Here to fill in your block of code;
/ /
)

if (expression)
(
/ /
/ / Here to fill in your block of code;
/ /
)
else
(
/ /
/ / Here to fill in your block of code;
/ /
)
Indent the code will generate the code easier to read, such as:
if (expression)
(
if (expression)
(
/ /
/ / Here to fill in your block of code;
/ /
)
else
(
/ /
/ / Here to fill in your block of code;
/ /
)
)
Notes and code for the establishment of the maximum length of the line in order to avoid having to scroll the source code editor, and can provide a hard copy of that order form.
Operators in most spaces before and after, it will not change the intent of the code. However, c + + in the use of the pointer that is an exception.
The use of a blank provided by the structure of the source code for clues. To do so would create a code "words" can help readers understand the logic of the software sub.
When the line is too long and must be changed when, in the back lines of code for use in indented format, as follows:
string inserString = "Insert Into TableName (username, password, email, sex, address)"
+ "Values ( 'Soholife', 'chenyp', 'soholife@sina.com', 'male', 'Shenzhen Futian')";

As long as the appropriate place of each line to avoid more than one statement. Exception is C, C++ + +, C # or jscript in the cycle, such as for (i = 0; i <100; i + +).
The preparation of HTML, a standard format for tags and attributes, such as all the tags are all uppercase or all lowercase attributes. Another approach is to adhere to XHTML specification to ensure that all documents are valid HTML. Despite the need to create a Web page file size to consider a compromise, but should be used with the attribute value in quotation marks and end tags to facilitate maintenance.
Prepared SQL statements, the use of all caps for the keyword, the database elements (such as tables, columns and view) the use of mixed case.
Between the physical file in a logical division of the source code.
Each major SQL clause on a different line, so that it easier to read and edit the statement, such as:
SELECT FirstName, LastName
FROM Customers
WHERE State = 'WA'
The complexity of the code will go a long paragraph into smaller, easy-to-understand modules.


Third, the Notes software to document the existence of two forms: external and internal. External documents (such as norms, to help document and design documents) in the source code of external maintenance. Internal documents from the developers in the development of source code in the preparation of the composition of the Notes.
Not consider the availability of external documents, as a result of hard copy documents may be misplaced, the list of source code should be able to exist independently. External documents should be standardized, design documents, change requests, error history, and the use of the composition of the coding standard.
Internal software document a problem is to ensure that the Notes and the maintenance and update of the source code at the same time. Although the source code of the correct notes in the run-time without any use, but for the need to preserve the particularly complex or troublesome software developer for the fragment is priceless.
The following points are recommended methods Notes:
If you use C # for development, use the xml document format, such as the Notes following methods:
/ / / <summary>
/ / / Get a person's age
/ / / </ Summary>
/ / / <param Name="userName"> user name </ param>
/ / / <returns> Users age </ returns>
public int GetUserAge (string userName)
(
/ /
/ / Here to write your code
/ /
)


Modify the code, so that the code is always around to keep up-to-date notes.
In the beginning of each routine, the provision of standard samples of the Notes to indicate the use of routines, assumptions and limitations helpful. Notes samples should be explained why it exists and what it can do a short presentation.
Avoid the end of lines of code to add the Notes; end-of-line comments make code more difficult to read. However, in a statement endorsed variables, end-of-line comments is appropriate; in this case, all the end-of-line comments in the public tab located at the alignment.
Notes to avoid clutter, the entire planet like a number. Blank should be used but will be separated from the Notes of the same code.
Notes avoid block box around with printing. This may seem beautiful, but difficult to maintain.
Prior to deployment, remove all temporary or not related to the Notes in order to avoid future confusion arising from maintenance work.
If you need to explain the complexity of using the Notes section of the code, please check the code to determine whether it should be rewritten. Notes does not do everything possible to understand the code, and it should be rewritten. Despite the general should not be more simple in order to code in order to facilitate the use of the expense of performance, but the performance and the need to maintain a balance between maintainability.
Notes in the preparation of the use of complete sentences. Notes should be clearly set out the code, rather than an increase of more than justice.
When writing code in Notes, because the future is likely to not have the time to do so. In addition, if an opportunity to review the code has been prepared, it seems clear today, things might not be apparent after six weeks of.
To avoid unnecessary or inappropriate comments, such as the humor is not the main Remarks.
Notes to explain the use of the intention of the code. They should not be used as an online translation of the code.
Note the code is not very clear of any content.
In order to prevent the recurring problem of bug fixes and solutions are always the use of code comments, especially in the team environment.
By branches of the cycle and the logic of the composition of the code uses the Notes. These are to help the source code of the main aspects of the reader.
Throughout the application, the use of punctuation and structure of the same style of uniform to construct the Notes.
Blank to use the Notes Notes separator to separate the same. In the absence of color prompted to view the Notes, the Notes that it will be obvious and easy to find.


.Net Object Oriented Programming Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.