Comments are text notes added to the program to provide explanatory information about the source code. They are used in a programming language to document the program and remind programmers of what tricky things they just did with the code and also helps the later generation for understanding and maintenance of code. The compiler considers these as non-executable statements. Different programming language uses a different way of including the comments in the source code.
Comments can be used for the various purpose like :
- Planning and reviewing : In comments, we can write the pseudocode which we planned before writing the source code. Pseudocode is a mixture of natural language and high-level programming language. This helps in reviewing the source code more easily because pseudocode is more understandable than the program.
In the above example, I have written the pseudo code of gcd in comments. This will help during the implementation of the code.
- Code description : Code description is used by the programmer to make others understand his/her intent. It contains the summary of the code.
- Algorithmic description : Comments are used for explanation of the methodology. Such explanations may include diagrams and formal mathematical proofs. This may constitute the explanation of the code, rather than a clarification of its intent. For example, a programmer may add a comment to explain why an insertion sort was chosen instead of a quicksort, as the former is, in theory, slower than the latter.
- Resource inclusion : Logos, diagrams, and flowcharts consisting of ASCII art constructions can be inserted into source code formatted as a comment. Further, copyright notices can be embedded within source code as comments.
- Metadata : Comments also contain metadata of the program. This metadata helps in software maintenance. The metadata includes the name of the creator of the original version, current maintainer of the program, data when the first version was created, the name of the people who have edited the program files so far etc.
- Debugging : Brute force method is a common method of debugging. In this approach, print statements are inserted throughout the program to print the intermediate values with the hope that some of the printed values will help to identify the errors. After doing debugging we comment those print statements. Hence comment is also used for debugging.
- Automatic documentation generation : Programming tools sometimes store documentation and metadata in comments. These may include insert positions for automatic header file inclusion, commands to set the file’s syntax highlighting mode, or the file’s revision number. These functional control comments are also commonly referred to as annotations. Keeping documentation within source code comments is considered as one way to simplify the documentation process, as well as increase the chances that the documentation will be kept up to date with changes in the code.
- Stress relief : Commenting on development tools, competitors, employers, working conditions, or the quality of the code itself are the ways to relieve stress. The occurrence of this phenomenon can be easily seen from online resources that track profanity in source code.
Learn more about Comments in C/C++, Java, HTML, C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org
- Electrode Potential Measurement
- Can a non executable program become executable
- When are children generally vaccinated for tetanus
- What is HEBA commerce
- Did Taiwan really attend Trumps inauguration
- Can I join CBSE at class 11
- Which Middle Eastern airlines fly to Pakistan
- Does Amazon deliver to IIT Roorkee
- What are appropriate classroom behaviors
- How do I find a sales partner
- Can monkey swim
- How do dogs make themselves throw up
- Is politics a good career choice?no_redirect=1
- Can we send information with photons
- Which cricketers have interesting alternate professions
- Why are spaceships provided with heat shields
- When does rationality contradict religion
- Why do we need client side code
- Why was Fleet Week cancelled 2013
- Is MIS a good major