So We’ve seen people often suggesting to comment while coding. Let’s together find out what the comments are and how are they really helpful.
“Comments” are the text that is being added to the computer programs to better understand the implementation logic.
In technical terms, “ A comment is a programmer-readable explanation or annotation in the source code of a computer program.” (source: wiki)
There is a phase where everyone thinks that “As I’ve written the code I can better understand it !! so what is the need of commenting? “
“Whom do the comments in my program help? “
Or to be simpler
“What is the use of writing comments? “
I’m gonna crack all these answers for you now…! :)
For instance, you’ve put your code in an open-source platform and users try to read it. What if they couldn’t cope up with the flow?
When we are writing smaller programs, it is okay to understand the code and logic with little hard work. But when we are trying to build larger applications where one file is linked to another or data is being rendered from other files, commenting can help you better understand the overview of code working.
The two important scenarios where comments help are :
- People who are referring to your code can easily go through the flow as the comments prevent one fight with the logic.
- You can understand your code when you read it after years (happens with most programmers ).
How should be the comments?
- Try to keep them relevant.
- Don’t write bigger comments, keep it short and simple.
- Don’t use it everywhere. ( Find the toughest code lines to comment).
For example, we are commenting an HTML file,
The comment should be in such a way that it should give a description (one line) about the tag and any ids or classes included in it.
So try to comment your code so that it helps for your future reference and also to those who are willing to refer your code.
I hope this helps you.
Do drop your feedback :)
Thank you guys. !