C # writing standards-code writing standards

Source: Internet
Author: User

Code writing specifications

Formatting makes the logic structure of the code very obvious. It takes time to make sure that the source code is formatted in a consistent logic, which is of great help to you and your development team and other developers who will maintain the source code in the future.

The following are recommended formatting methods.

  • Create a standard indent size (such as four spaces) and use this standard consistently. Align the code section with the specified indentation.
  • Use a specific font and font size when releasing a hard copy version of the source code (New ,, ).
  • Align the Left and Right brackets vertically at the positions of the brackets, such:

For (I = 0; I <100; I ++)

{

;

}

You can also use the skewed style, that is, the left parenthesis appears at the end of the row, and the right parenthesis appears at the beginning of the row, such:

For (I = 0; I <100; I ++ ){

;

}

Regardless of the selected style, use that style throughout the source code.

  • Indent the code along the logical structure line. Without indentation, the Code becomes hard to understand, such:

If (expression)

{

//

// Enter your code block here;

//

}

 

If (expression)

{

//

// Enter your code block here;

//

}

Else

{

//

// Enter your code block here;

//

}

Indent code generates code that is easier to read, such:

If (expression)

{

If (expression)

{

//

// Enter your code block here;

//

}

Else

{

//

// Enter your code block here;

//

}

}

  • Create the maximum line length for comments and code to avoid having to scroll through the source code editor and provide a neat hard copy representation.
  • Spaces are used before and after most operators. In this case, the intent of the Code is not changed. However, the pointer representation used in C ++ is an exception.
  • Use blank space to provide structure clues for source code. This will create code segments to help readers understand the logical segments of the software.
  • When a line of content is too long and must be changed, the indent format should be used in the next line feed code, as shown below:

String inserstring = "insert into tablename (username, password, email, sex, address )"

+ "Values ('soholife', 'chenyp', 'soholife @ Sina.com ', 'male', 'shenzhen Futian ')";

 

  • If appropriate, avoid placing more than one statement on each row. The exception is a loop in C, C ++, C #, or JScript, such as for (I = 0; I <100; I ++ ).
  • Standard tag and attribute formats are created when HTML is compiled. For example, all tags are in upper case or all attributes are in lower case. Another method is to adhere to the XHTML specification to ensure that all HTML documents are valid. Although the file size needs to be compromised when creating a web page, attribute values and ending tags with quotation marks should be used for easy maintenance.
  • When writing SQL statements, all keywords are capitalized, and database elements (such as tables, columns, and views) are case-insensitive.
  • Logically divide source code between physical files.
  • Place each major SQL clause on different rows, which makes it easier to read and edit statements, for example:

Select firstname, lastname

From MERs

Where State = 'wa'

Divides large complex code segments into small and easy-to-understand modules.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.