Tip: Use Comments In Your Code

Tip: Use Comments In Your Code

By Daniel J. VandeBunte

Writing a successful program requires a clear thought process about what the program will do. One thing beginning coders should get in the habit of doing is using code comments to guide their thinking as they write their program. Every programming language I have ever used has had some convention for inserting comments into code. Comments do not get interpreted by the program as lines to execute. But they serve a number of purposes.

  1. They serve as the outline of your program. Statements that you can easily read to remind you of what you are trying to do, what you need to do, and how to do it.
  2. They serve as a guide to others who may also have access to your source code. If you share your code or work collaboratively with others, comments help explain changes you or others have made.

Here is a script I wrote that makes ample use of comments to explain what is going on. The script is used with a form and spreadsheet. The form is given to my classes on the first days of school and collects their GAFE email address automatically. If you do not teach in a GAFE school, you will have to collect their email address with a form question. Hopefully, they enter it correctly. The source code may also have to be updated to collect that email address from the correct column in the spreadsheet.

The student adds their first and last names and which period during the day they have me. The periods are provided as a multiple choice question in the form and each choice corresponds to a GMail contact group. The script automatically adds the student to a GMail contact group with the same name as the period they choose.

A trigger is then created to run the script each time the form is submitted.

Leave a Reply

Your email address will not be published. Required fields are marked *