Comments are useful in programming languages?

Prince Agrawal
4 min readOct 18, 2022

--

Photo by Luca Bravo on Unsplash

When we are working on an existing software project, There’s always a mesh up, we are not able to know why this code is written here. we all experienced that problem in our development carrier. So it’s always been suggested to write comments to tell, why we are written this piece of code.

So let’s started to learn how to write comments on various programming languages.

Uses of comments in programming:

  • Comments can be used to explain the code, and to make it more readable for someone who is looking at the code.
  • Comments can also be used to prevent execution, when testing alternative code.
  • Comments can be used to document your coding, if file sizes grows it will be helpful to understand the code. You can comment on variables, functions, statements and loop…
  • Comments are also too helpful for you to remind the code when you start editing the code after long time.
  • Comments can remind you of what you were thinking when you wrote the code.

HTML

<!-- Write your comment here -->

There is only one way to write comment in HTML.

Anything inside this <!- - and --> will not be rendered by the browser.

CSS

CSS supports one type of comment for both single and multi-line comment.

/* Your comment goes here */

Like HTML, CSS comments are also not rendered by the browser. CSS comments must be used either inside the style tag <style> or external style sheet only.

JavaScript

JavaScript supports 2 types of comment.

Single line comment in javascript:

// Your comment goes here

Anything starts after // till end of the line will be ignored by javascript.

Multi line comment in javascript:

/* Your comment goes here */

Anything between /* and */ will also ignored by the javascript.

SASS

Unlike CSS, SASS supports 2 types of comments.

Single line comment in SASS (also called silent comment):

// Your comment goes here

Anything starts after // till end of the line will be ignored by sass, and not produced any CSS comments.

Multi line comment in SASS (also called loud comment):

/* Your comment goes here */

Multi-line comments start with /* and ends with */ and anything between this will be ignored by sass compiler. Multi line comments compiled to CSS comment in non compressed mode.

NOTE: By default multi line comments are also stripped from the compiled CSS in compressed mode. So if a comment begins with /*! and ends with */, though, it will always be included in the CSS output.

PHP

PHP supports 2 types of comment.

Single line comment in Php:

There are two ways to write single line comment.

// Your comment goes here

OR

# Your comment goes here

Anything starts after // or # till end of the line will not executed.

Multi line comment in Php:

/* Your comment goes here */

Anything between /* and */ will also not executed.

Python

Python supports comment in little different manner.

Single line comment in Python:

# Your comment goes here

Multi line comment in Python:

Python does not have a different comment for multi line.

# Your comment1 goes here
# Your comment2 goes here
# Your comment3 goes here

NOTE: Since Python will ignore string literals that are not assigned to a variable, you can add a multi line string (triple quotes) in your code, and place your comment inside it:

"""
Your multi-line
comment goes
here
"""

JAVA

Java supports 2 types of comments.

Single line comment in Java:

// Your comment goes here

Anything starts after // till end of the line will not executed by java compiler.

Multi line comment in Java:

/* Your comment goes here */

Multi-line comments start with /* and end at the next */ and anything between this will not executed by Java compiler.

C

C supports 2 types of comments.

Single line comment in C:

// Your comment goes here

Anything starts after // till end of the line will not executed by C compiler.

Multi line comment in C:

/* Your comment goes here */

Multi-line comments start with /* and end at the next */ and anything between this will not executed by C compiler.

C++

C++ supports 2 types of comments.

Single line comment in C++:

// Your comment goes here

Anything starts after // till end of the line will not executed by C++ compiler.

Multi line comment in C++:

/* Your comment goes here */

Multi-line comments start with /* and end at the next */ and anything between this will not executed by C++ compiler.

SQL

SQL supports 2 types of comments.

Single line comment in SQL:

-- Your comment goes here

Anything starts after --till end of the line will not be executed by SQL.

Multi line comment in SQL:

/* Your comment goes here */

Multi-line comments start with /* and end at the next */ and anything between this will not be executed by SQL.

MySQL

MySQL supports 2 types of comments.

Single line comment in MySQL:

-- Your comment goes here

Anything starts after — till end of the line will not be executed by MySQL.

Multi line comment in MySQL:

/* Your comment goes here */

Multi-line comments start with /* and end at the next */ and anything between this will not be executed by MySQL.

Thanks for reading. and please share with your friends.

--

--