10. Many contemporary languages allow two kinds of comments, one in which delimiters are used on both ends (multiple-line comments), and one in which a delimiter marks only the beginning of the comment (one-line comments). Discuss the advantages and disadvantages of these.

Respuesta :

Answer:

Advantages and Disadvantages of one line comments

  • Comments make the program readable and understandable.
  • Single line comments can be used to add a comment to each line of the source code.
  • Using only single line comments can save a person from forgetting to close delimiters when using multiple line comments.
  • Single line comments make code more understandable as it briefly defines what is the purpose of a specific line of code.
  • For example:     if(sal<10000) // checks if salary is less than 100000
  • Single line comments are beneficial to use when a function name does not exactly tells what that intends to perform.  
  • These comments are ignored by compiler and they don't affect execution speed.
  • However using too much single line comments with understandable lines of code is not a good practice and might result in redundancy.
  • Also using too many irrelevant single line comments is not good.
  • Single line comments can also comment out or hide certain lines of source code. The compiler wont read that line of code as it takes it as a comment. This is a benefit as that line of code can be used later in the code by removing the delimiter.
  • One of the major disadvantages of using a one line comment is that the delimiter has to be added before each line if the explanation of a specific line of code exceeds from a single line. This would be difficult as well as error prone.

Advantages and Disadvantages of multiple line comments

  • Sometimes it is required to explain a whole block of code within a source code which gives better description than commenting on each line of that block which might lead to confusion regarding the purpose of that block of code. So using multiple line comments helps describe the purpose of the whole block of code within a program.
  • Sometimes it is required to give a general description of a code than to go into unnecessary details of each line which might be equivalent to repeat the code itself. So multiple line provides with higher level abstractions just giving a brief description of the intent of the code.
  • One advantage is that they are used to comment out or hide the whole block of code. While single line comment has to use the delimiter repeatedly to comment out the block of code, multiple line has starting and ending delimiters to comment out the whole block without using delimiter for each code line. This is used for testing purposes.
  • One of the disadvantage is that too much lines of the comments takes space on the screen and moves the real code off the screen, which sometimes makes the code hard to read and understand as a whole because too multiple line comments are taking screen space.
  • The major disadvantage is sometimes the closing delimiter of multiple line comments is forgotten to add while ending multiple line comments. So if these comments aren't closed it will lead to errors in a source code when compiler/interpreter reads these lines as well and also  could result in the code to be commented out if the delimiter is closed in the wrong part of the program.
ACCESS MORE