Comments in the Source Code
One-line comments are often found in the source code. They serve to explain certain commands or constructs. A one-line comment is indicated by two
// I am a comment int led = 1; // variable 'led' gets the value 1
Multi-line comments are often at the beginning of a program or a method. They begin with
/* and end with
*/. You can also use them to comment out parts of a program. For example, if you have an error and want to check in which part of the program it is.
/* * * I am a multi-line comment. * For instance I can declare the use of the whole program or * of a single method. * * By the way: * <- these stars are automatically created when writing a multi-line comment, * but they are no necessesity * */
How Many Comments Does a Source Code Need?
That is a question for which there is no clear answer. There are programmers who expect every line of code to be commented on. This is not necessary with our simple programs. Basically, at least the following program parts should be commented on:
- A comment at the beginning, which describes the purpose of the program.
- Each method must be commented on, and in particular the input parameters and possible returns.
- Mathematically or logically demanding commands or special 'gimmicks' that the programmer has considered.