How to write a comment

xiaoxiao2021-03-06  77

Introduce you a little knowledge (saying is a little knowledge, but the relationship is high) how to write a comment. I have always been more confused to read what I want to write. I often have a lot of attention, but I find a little information when I look back. nor

Generally, the comments we have said are for functions (that is, methods), because the function is the minimum unit of modular design (class is still not a minimum unit) a function means a function, so the function's annotation is at least two : 1. This function can get the correct results in the case, such as open square functions, parameters cannot be negative. This is called 'leading condition', it is recommended to indicate the beginning of the method, like this: void xxx () { // pre: Pre-conductor} is not all functions have a preamble, and some functions can be properly resulting in any case, such as the addition of the addition. So, sometimes the preamble can not write 2. After this function is executed What effect will cause. For example, set a state of an object or return a value. This is called 'back condition', it is recommended to indicate in the end of the method, like this: void xxx () {.... // POST: All functions have a back condition. Because a function is called, it will definitely affect, otherwise this function does not exist. Be sure to write the back condition of each function. 3. If there is a function of each function. The formula or theorem is used, and the americ or formula is used in the comment, it is best to pay a brief description of the formula or theorem. (Of course, if it is a simple, it is not said) 4. If a piece of code is unpredictable, it is to be indicated, like this: ... # 隔 一 / 处理 处理 x x / / 行 d d 处理 处理 处理 处理 处理 处理 处理 处理 处理; // 3rd: xxx ...; #sorship .....

Pay attention to these points, you should not encounter what you don't know, or your comments are not nonsense (I often like this).

Note: The annotation written when writing code is worth it. If you have finished comment after the code is written, then don't make it again, you can write into the documentation to write. Note requires that the programmer write the program The thinking process is just that I am personal coding habit, mainly introducing some details that you need to pay attention to writing comments.

转载请注明原文地址:https://www.9cbs.com/read-92497.html

New Post(0)