Comments
Throughout the previous exercises and examples you will have seen that in some cases comments have appeared in the programs.
A comment in programming is text in our source code that the compiler ignores. And if you ignore it, why do we put it on? Usually to give us internal explanations of what the function of each part of the program is. They are also very useful for temporarily discarding code fragments, without having to delete them, and thus facilitate their later recovery.
Comments in programming are essential:
- They facilitate understanding: not only of other users but also of the programmer himself throughout the duration of the development of the program.
- They encourage collaboration: they make the code understandable for other co-programmers who can also participate.
- They facilitate error debugging: commenting and uncommenting code fragments will allow us to detect where errors are occurring.
Comments in Scratch
In Scratch you can add comments from the code editing window associated with each object. Comments can be either associated with a block or on the editing window itself. They are added by right-clicking on the place where we want to insert the comment.
Once added, they remain as visible notes in the code editing area.
Of course in Scratch there is no option to comment and uncomment blocks so that they are not taken into account by the compiler. The option available to do this is to separate the event that determines the execution of that block and the code will be temporarily deactivated.
Comments in PSeInt
To make comments in PSeInt we will simply have to head the point where we want to insert the comment with a double slash. That will put the text that follows in a pale gray and in italics, which will indicate that the compiler will not take into account what is written in this way.
Comments can also be entered at the end of a line of code.
PSeInt only allows commenting on lines and not entire fragments of code, so if we want to discard a set of instructions we must comment line by line on all those that make up the block. That obviously does not happen in structured programming languages that do have this capability.
This capability is especially useful in debugging phases, to isolate the code fragments where errors are found.
The comments of course do not appear in the program execution window. Where they are visible is in the associated flowchart.