+ 2
If comments are not displayed, then how exactly do they help?
8 Respostas
+ 7
Here is a good and readable example of comment. Actually, this programme is a course, so the interest is not to be run but to be read.
At your level, don't try to understand, but you'll see easily the interest of the comment.
https://code.sololearn.com/c5qxQK1U0x2U/?ref=app
+ 4
Well bro comments help in explaining the code lines .
They are not executed but help the other humans to understand the lines of code .
Thanks
+ 4
Comments are visible for everyone who reads your code ;)
The more complex your code gets or the more people have to work with your code, the more important it is to use informative comments in order to allow others (and yourself, after some time has passed) to understand what a function etc. is intended to do.
Some languages like Python allow to display certain kinds of comments (docstrings) even without seeing the actual code:
Sample code:
def myfunction():
"""This function does some very complex calculations...
It expects the following parameters: ...
The return value is ..."""
# actual code goes here...
pass
If a user or other coder enters "help(myfunction)", they will see the following output:
Help on function myfunction in module __main__:
myfunction()
This function does some very complex calculations...
It expects the following parameters: ...
The return value is ..."""
+ 3
Masher here is the thing. Comments are used to specify to the reader about what a particular line of code or a set of lines or a particular function does.
It is definitely not displayed as they are removed/eliminated by the compiler (lexical analyzer to be specific). But when a person reads a code, comment lines help him/her understand the functionality of the code (what a block of code or a line of code does and why that block or line of code is used).
It may seem very stupid for a small code of about 50-100 lines but for a complex code having hundreds of functions and thousands of lines, comment lines help in better understanding of how the code will run and how it was built.
+ 2
Comments mean that user can understand what does code mean and make you not forget or confusing.. and it's not affected your output or code. So don't worry hehe..
Thank you.
+ 1
So they can be seen? I mean how can something that's not displayed help you? I'm a beginner so just help me😁
+ 1
Thanks everyone:)