To truly understand something, you have to teach it...
Programming languages have comments — a way for the programmer to leave notes for humans in the code. Comments are invisible to the computer, and don't do anything.
Except make your code not suck.
Comments are enclosed by codes that are different for each programming language. In our course, we will be using four kinds of comments:
<!-- HTML lets us put multi-line comments inside these... -->
Cascading Style Sheets (CSS):
/* CSS lets us put multiline comments inside the slash-star */
several lines with slash-star, too. */
The main point of comments is to help explain and structure your code so that it helps you stay organized. It also helps you communicate clearly to any human who may have read your code, including your co-workers, your employer, and even yourself, after enough time has passed.
It is considered unprofessional to create uncommented code. Think of comments as your way to teach others what is going on in your code. Treat the reader like they are a beginning programmer.
Use comments to...
- Explain what your code is doing
- Explain what your data structures contain
- Record when you modified your work (help justify your paycheque)
- Give examples of how your code could be used
- Keep a todo list
- Keep a list of feature ideas
- Keep a list of bugs to fix
- Keep a list of questions to ask your teacher
An example of the four kinds of comments
- Khan Academy on HTML comments