Interpretation of code Daquan (6)

Source: Internet
Author: User

Interpretation of code Daquan (6)

 

Today, I spent some time reading two more chapters: Chapter 1-document and Chapter 2-notes. I thought it would be easy to look at it. while reading it, I felt that a lot of code I wrote was really rubbish, and there were a lot of bad smell. These two chapters are actually a core issue. To write comments, you do not need to write comments. I don't want to discuss them too much, but how to write comments is a problem for us.

I have summarized the following points:

1. Do not write useless comments

For example, if (Var = 0) // If the variable is equal to zero

This is useless because it does not reflect more information than the Code itself. Better:

If (Var = 0) // if no data is read

Annotations are specific business rules.

2. Use the PDL mentioned in the previous chapters (program process description language), but I still think that there is currently no good tool to use.

3. Special cases must be described. For example, if you call a function with a specific exception, you must explain the cause of the exception.

4. Note the special constants. Although constants or macros are generally recommended in popular language manuals, it is best to add a line of comment after the definition so that others can understand why you need to use the constant.

5. It is very interesting that you are not recommended to use beautiful comments, but difficult to maintain, in this book. Many programmers like to add a text logo before the code, but it takes some time for maintenance.

6. Description of the algorithm. For a complex algorithm, it is best to write some basic information. Do not "decompile" your algorithms from the code.

Finally, exercise more and don't let the comrades watching your code swear. Of course, your code is not an exception for people to understand. Haha.

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.