The method of construction--read Note two

Source: Internet
Author: User

Read note Two-code specification

The code of the style of the principle is: concise, easy to read, no ambiguity. Although I am a computer science student, but I did not have this principle to write code, now read the construction of the law, I understand how to make your code concise, easier to understand.

The code is noted in the process of writing:

  1. Indent with TAB key
  2. Note the line width, up to a limit of 100 characters line width
  3. In complex conditional expressions, the logical precedence is clearly expressed in parentheses
  4. Note the {} lines with a line break and blank, with the explicit "{" and "}" to determine the structure of the program
  5. Do not put too many statements on the same line
  6. The name of the variable should have a practical meaning
  7. Use underscores to delimit scope labels and the semantics of variables in variable names
  8. Variable names that are made up of multiple words in case
  9. When writing code, be sure to have comments so that others are easy to understand when you look at your code, and that you can easily see your code later.
  10. When writing a program, be sure to add error handling according to the actual situation, your code becomes more perfect, avoid unnecessary bugs.

Since reading this section, I am deeply ashamed, although I am a computer department student, but I have written before the code opportunity does not conform to any of the above, resulting in my code looks very messy, when the program error, do not know how to start, where to find the wrong, Whenever I let my classmates help me to change the wrong time people are reluctant to think that my code is too messy, variable definition is unclear, the structure is very chaotic. But since I've changed this rule, the code I've written actually seems to be a lot easier to read, to make myself look pleasing, rarely to lose parentheses again, and to use the wrong variable as a low-level mistake.

Writing good rules, neat code, is a good software engineer's first step.

The method of construction--read Note two

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.