Home > Common Problem > body text

How to add code comments?

青灯夜游
Release: 2019-04-19 11:04:52
Original
17681 people have browsed it

You can pass in the code: //comment, /*comment*/, , #comment, '''comment''', --comment, 'comment, %comment and so on to add comments. The following article will introduce you to the methods of code annotation by category. I hope it will be helpful to you.

How to add code comments?

Common code comment methods:

HTML comments

<!--这里是注释-->
Copy after login

CSS Comments

/*这里是注释*/
Copy after login

JavaScript Comments

Single Line Comments:

//这里是注释
Copy after login
Copy after login
Copy after login

Block (Multiple lines) Comments:

/*这里是注释*/
Copy after login
Copy after login
Copy after login

XML Comments

<!--这里是注释-->
Copy after login

C/C /C# Code Comments

Single-line comments:

//这里是注释
Copy after login
Copy after login
Copy after login

Block (multi-line) comments:

/*这里是注释*/
Copy after login
Copy after login
Copy after login

Java comments

Single-line comments:

//这里是注释
Copy after login
Copy after login
Copy after login

Block (multi-line) comments:

/*这里是注释*/
Copy after login
Copy after login
Copy after login

Python comments

Single-line comments:

#这里是注释
Copy after login
Copy after login

Block ( Multiple lines) Comment:

&#39;&#39;&#39;这里是注释&#39;&#39;&#39;
Copy after login

VB comment

&#39;这是一个单行注释
Copy after login

Note: It is a single quote followed by the comment

perl comments

Single line comments:

# 这是一个单行注释
Copy after login

Block (multiline) comments:

=pod 
这里是注释
=cut
Copy after login

Matlab comments

Single-line comments:

%这里是注释
Copy after login

Block (multi-line) comments:

%%这里是注释%%
%{这里是注释%}
Copy after login

R language comments

Single-line comments:

#这里是注释
Copy after login
Copy after login

Block (multi-line) comments:

if(false){这里是注释}
Copy after login

Why add comments?

Comments are "hints" or "explanations" of the code, not documents; comments are mainly used to explain code complexity; comments should be accurate and easy to understand (unambiguous) sex), concise; the amount of effective comments in the program must be more than 20%. It is definitely a good habit to add comments to the code. It is best to comment while writing the code

The purpose of comments: to facilitate the maintenance of the code, explain the functions and methods of the code, facilitate readers to read, and prevent unnecessary duplication of information .

Note: If the code is clear and self-explanatory, there is no need to add comments. Overly detailed comments can easily make people bored. Remember not to think that others cannot understand it without adding comments.

The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of How to add code comments?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template