Which Is Better Too Many Comments Or Too Few Comments?

Are code Comments bad?

Code comments are definitely not a “code smell”.

This belief typically comes from the fact that comments can become stale (out of date) and can be difficult to maintain.

However, having good comments which explain why the code is doing something a certain way can (and usually is) important for maintenance..

Why are Python comments important?

Comments can be used to explain Python code. Comments can be used to make the code more readable. Comments can be used to prevent execution when testing code.

What is the difference between commenting code and code documentation?

A comment is often used to explain a small part of some code which ight not be directly obvious. This is something targeting other developers working directly with this code (e.g. refactoring it). A documentation is often focused on some third party user. … A documentation is also often something external.

What is comment give an example?

1. A comment is text in a program’s code, script, or another file that is not meant to be seen by the user running the program. … Comments help make code easier to understand by explaining what is happening and help prevent portions of a program from executing. The image is an example of an HTML comment.

Should I comment every line of code?

Three lines of comment for every line of code would not be excessive. For actual code, it would be much lower. I don’t agree with the extremists who think you should aim for zero comments, but certainly if you think you need comments you should first consider whether the code could be made clearer.

Should code have comments?

A handy rule of thumb is: a comment should only be added to answer a question that the code can’t. If you aren’t confused by what a piece of code is doing, but rather why it’s doing it at that moment, then a comment should be added.

What do you mean by comments?

: a spoken or written statement that expresses an opinion about someone or something. : a written note that explains or discusses the meaning of something (such as a piece of writing) : spoken or written discussion about something (such as an event in the news)

How do you put a code in notes?

Google Docs Syntax Highlighting and Taking NotesStart a new Google document, paste or write some codes.Click Add-ons -> Code Blocks -> Start.Highlight the codes you want to syntax highlighted, then click preview or format and it will appear as above.More items…•

How do you put a comment in code?

Comments can be added to single lines of code (Ctrl + /) or blocks of code (Ctrl + Shift + /). In addition, special PHPDocBlock comments can also be added. See “Adding PHP DocBlock Comments” for more information. The following procedures describe how to comment and uncomment lines and blocks of code.

How do I comment out HTML code?

To comment out in HTML, insert information between tags (browsers won’t show these notes). Commenting in HTML allows developers to leave notes about their code, its functionality or to indicate necessary changes for the future.

Why is it important that code be well commented and well formatted?

So, the well commented functions/logics are helpful to other programmers to understand the code better. They can easily understand the logic behind solving any problem. If you see/edit code later, comments may help you to memorize your logic that you have written while writing that code.

What is the purpose of comments?

In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program. They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters.

Can you over comment code?

Failing at anything, you can always delete superfluous comments from the code; however, you can not derive meaning from them if there are none there to begin with. I’ve heard some developers argue that other developers that “over document” (definitions of this vary by person) their code are not good developers.

How are comments considered a code smell?

Comments are usually created with the best of intentions, when the author realizes that his or her code isn’t intuitive or obvious. In such cases, comments are like a deodorant masking the smell of fishy code that could be improved. The best comment is a good name for a method or class.

When should you use comments?

Commenting is the “art” of describing what your program is going to do in “high level” English statements. Commenting is best done before actually writing the code for your program. Comments are specially marked lines of text in the program that are not evaluated. There are usually two syntactic ways to comment.

How much should I comment my code?

That is a cool question and I know the answer! You should comment exactly as much as you love your work! If you love your code a lot; go ahead and write your heart out all over the code. If you do not love your code at all, please do not write any comments, no one needs any more from you!

What are the two types of comments?

We have two types of comments here, the end-of-line comment and the block comment. An end-of-line comment terminates at the end of the line. A block line comment has a terminator and can continue for several lines, or be less than one line. Comments were called REMarks in BASIC.