Comments
Memory is short—by writing we preserve It
As programs grow, it becomes harder to remember what each part does and why it was written that way. A comment is a note left in the code for humans to read. CSP ignores comments completely, so they never change what a program does.
Writing a Comment
A comment begins with two forward slashes (//). Everything after the slashes on that
line is part of the comment.
- Comment (noun)
- A section of code for humans only that the language ignores
Only the second line runs here. The first line is skipped entirely.
A comment can also share a line with code. CSP runs the code, then ignores everything
after the //.
To write a comment that spans multiple lines, start each line with its own //.
Slashes inside a string are just text, not a comment.
DISPLAY("a // b")displaysa // b.
Using Comments Well
Good comments explain why the code does something, not just what it does. The code already says what it does. Compare these two comments.
The first comment only repeats the code. The second tells the reader something new.
Comments are also useful for temporarily disabling a line of code without deleting it. This is called commenting out code.
Remove the // and the line runs again.
Comments in Other Languages
Not all languages use \\ to denote comments. See below for some various comment types.
Next: Conditionals