how to program
HOW TO PROGRAM . IT - learn how to program - online interactive programming tutorial and programming course
Do Not Over-Comment

Lesson 04: Too many comments can get in the way, use your judgement. Are they necessary, or in simple situations are they merely stating the obvious and getting in the way?

Comments which just show what is being done can be redundant if the code itself is already showing what is being done. This is one of the concepts of self-documenting code, and as such it is my opinion that programs should be written in a way that make them as easy to understand and as self-documenting as possible, only adding comments where necessary that provide information the code itself does not provide. I would much prefer to see an easy to understand self-documenting program with minimum comments, rather than a difficult to understand, non-self-documenting but 'well commented' program. This will be discussed in more detail in future lessons.

The following code demonstrates the previous example code without any comments...

Program Code:

In future lessons we will try to minimise comments, and instead try to make the code as self-explanatory as possible. Simple code without comments is fine, and since this is a beginners course, the code will be simple. Since this is a programming course, description of the code will be provided anyway in introductory text.


1. Does the code read better with the line spaces or without? Delete the line spaces.

To return to previous page click here

by running the tutorial programs on this site, you are agreeing to our terms and conditions (please check these first).
Thu 27 Jan 2022 web design | login © 2022 Abstract Worlds Ltd