Google C + + Programming style Guide (vi): code comments

Source: Internet
Author: User
Tags comments documentation

Comments

Annotations are painful to write, but are important to ensure the readability of the code, and the following rules describe what should be commented on and where the comment is. Remember, of course, that annotations are really important, but the best code in itself is the document (self-documenting), and the type and variable naming sense is much better than the ambiguous naming through annotations.

Comments are written for someone else (the next person who needs to understand your code), seriously, the next person may be you!

1. Annotation style (Comment style)

Use//////* *, unified.

OR//* * can be,//only used more widely, in how annotation and annotation style to ensure unity.

2. Document annotation (file Comments)

Add a copyright notice at the beginning of each file, followed by a description of the file content.

Legal notices and author information:

Each file contains the following items, followed by:

1 Copyright (statement): such as copyright 2008 Google Inc.;

2) licensed version (license boilerplate): Select the appropriate license version for the project, such as Apache 2.0, BSD, LGPL, GPL;

3 Author (author line): Identifies the original author of the file.

If you make a significant change to a file created by someone else, add your information to the author's message so that anyone who has questions about the file can know who to contact.

File contents:

After each file copyright license and author information, the contents of the file should be annotated.

Typically, the. h file has a simple description of the functionality and usage of the declared class. The CC file contains more implementation details or algorithmic discussions, and if you feel that the implementation details or algorithmic discussions are helpful for reading, you can put the comments in. h in. CC and point out the document in. h.

Instead of copying annotations between. h and. CC, the copied annotations deviate from the actual meaning.

3. Class annotations (classes Comments)

The definition of each class adheres to a comment describing the function and usage of the class.

// Iterates over the contents of a GargantuanTable.Sample usage:
// GargantuanTable_Iterator* iter = table->NewIterator();
// for (iter->Seek("foo"); !iter->done(); iter->Next()) {
// process(iter->key(), iter->value());
// }
// delete iter;
class GargantuanTable_Iterator {
...
};

If you think you've already described the class in detail at the top of the file, you want to simply come up with a "full description of the top of the file," or how much to add a note to the class.

If the class has any synchronization prerequisites (synchronization assumptions), the documentation describes it. If an instance of the class can be accessed by multithreading, be sure to note the documentation when you use it.

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.