List three instances when comments should be used in a program. Why are comments important to a program? Should comments be used for every line of code?

What will be an ideal response?


Comments are typically used in these four situations (student should list at least three):
1. To begin a program with a statement of purpose or to orient a programmer called on to modify the program in the future.
2. To accompany a variable declaration with a comment that explains the variable's purpose.
3. Preceding major segments of code with a comment that explains their purpose.
4. To explain complex or tricky sections of code.

Comments are important to explain your code to a new programmer updating or maintaining a program you wrote, or to remind yourself in the future about nuances of the program.

Comments should not be used for self-explanatory lines of code.  Overuse of comments makes the program unwieldy to update and confusing to read. The best-written programs are self-documenting; that is, the reader can understand the code from the symbols used and the overall organization of the program.

Computer Science & Information Technology

You might also like to view...

What is the InDesign filename extension?

A. .id B. .indd C. .ind D. .inde

Computer Science & Information Technology

Markers placed in an application to indicate the program should halt execution when it reaches that spot is a ____.

A. breakpoint B. break mode C. debug point D. debugger spot

Computer Science & Information Technology

The activities that ensure compliance are typically arrayed into a formal ____.

A. management infrastructure B. security infrastructure C. maintenance infrastructure D. control infrastructure

Computer Science & Information Technology

When an object is passed as an argument to a method, what is passed into the method's parameter variable?

a. the class name b. the object's memory address c. the values for each field d. the method names

Computer Science & Information Technology