A comment is a special construct in a programming language that allows the program developer to mention additional information associated with the program. This information could include the following:
The main reason for including comments in programming languages is for improving the portability and maintainability of a code. Often, software development teams work together on different software modules, which are inspected by testing engineers during the testing process. During the process of testing, the engineers have to be aware of the workings of a module. Hence, comments are included by the developer to explain the workings of a particular module by stating the valid types of inputs, the number of inputs, the algorithm used for processing in the internal module, the expected outputs and the error conditions that may be encountered during processing. Comments have many advantages. They denote the use of a particular variable when they are included in the line where the variable is first created. They also mention the purpose of a class if they are included adjacent to the class definition. For example, consider a function that withdraws money from a user's bank account. In this case, the inputs are the user's account number and the money that needs to be withdrawn. The account number is a general string of characters, whereas currency might be treated as an integer or a decimal. The output produced by the program would indicate either a successful withdrawal or not, along with the money requested for withdrawal. The function works by subtracting the money requested by the user from his previous balance. Error conditions may be encountered if the user wants more money than his or her current balance. Comments may be included at appropriate locations to document the above data. Comments also provide useful information regarding the author of the content, the date and time it was developed and the date and time it was last modified.
Read More »
Get Techopedia delivered to your inbox!