What should I comment on code?

What should I comment on code?

How to comment Code: Primarily, a single “block” comment should be placed at the top of the function (or file) and describe the purpose the code and any algorithms used to accomplish the goal. In-line comments should be used sparingly, only where the code is not “self-documenting”.

Is it a problem to have comments in code?

It tells you that your code is too complex. You should strive to remove clarification comments and simplify the code instead because, “good code is self-documenting.” But when you write a funny comment to make up for bad code, it actually makes people less likely to refactor and fix the code later.

How do you add comment code?

PDT allows you to quickly and easily comment and uncomment code by selecting a line or a block of text and tagging it as a comment. Comments can be added to single lines of code (Ctrl + /) or blocks of code (Ctrl + Shift + /).

Is Commenting code good practice?

A comment before the function (or element) is good for organization and clarity. More than that should go into the documentation. If you feel like it’s necessary to document, something like this will suffice.

How do I comment out HTML code?

To “comment out” in HTML, simply place the < ! ╌ ╌> tags around the code you want to hide. These tags will tell browsers not to render this code on the front end. Commenting out has two main purposes.

Which commenting combination is correct for commenting out a block of code?

To comment out a block of code, use // on multiple lines of code, or the /* */ style comment to turn the block of code into a comment temporarily.

How do you comment out lines?

To comment a line:

  1. Place the cursor anywhere on the required line of code.
  2. Press Ctrl + / Two slashes “//” will be added to the front of the line, causing it to be recognized as a comment.

What is the best way to comment out a section of code that contains comments?

A comment starts with a slash asterisk /* and ends with a asterisk slash */ and can be anywhere in your program. Comments can span several lines within your C program. Comments are typically added directly above the related C source code.

When do you not need to put a comment in code?

Most coders would chuckle and move on, ignoring the code smell. There are also times when you come across a comment that is redundant. If the code is already simple and obvious, there’s no need to add a comment. Like, don’t do this nonsense:

When to write funny comments to make up for bad code?

Don’t get me wrong, there are times — especially when you are slogging through a crushing workload — where injecting a bit of humor can be good for the soul. But when you write a funny comment to make up for bad code, it actually makes people less likely to refactor and fix the code later.

Why do you put clarification comments in your code?

Clarification comments are intended for anyone (including your future self) who may need to maintain, refactor, or extend your code. Often, a clarification comment is a code smell. It tells you that your code is too complex. You should strive to remove clarification comments and simplify the code instead because, “good code is self-documenting.”

What are the different types of code comments?

For starters, there are really two different types of code comments. I call them documentation comments and clarification comments. Documentation comments are intended for anyone who is likely to consume your source code, but not likely to read through it.