CS101 Style Guide

Getting the computer to understand your program is no guarantee that people will be able to follow it. Just as you would edit an English composition, you should spend time revising a computer program to make it elegant and readable. The following guidelines will help you write programs that are easy to read and modify. Beginning with Lab 2, the CS101 graders will expect your assignments to conform to these style and documentation conventions.

0. Put a cover sheet on your lab.

For every CS101 lab you turn in, you should fill in a cover sheet and staple it on the front of your lab. You can either print out the cover sheet or pick one up from the stack on top of the CS101 mailbox.

1. Include a header comment at the top of each file.

The file header should include some standard information, followed by a brief description of the contents of the file and any special assumptions you have made.

2. Write self-documenting code.

3. Follow standard formatting conventions.

4. Use inline comments sparingly but whenever necessary.

5. Present your test cases clearly and methodically.

Many of the CS101 labs ask you to prepare a series of test cases to demonstrate that your program behaves in accordance with the specification in the assignment. The following guidelines should be followed in preparing test cases.

6. Use common sense.

Remember that the CS101 style guide is only a guide. Your primary concern should be making sure that others can read and understand the text of your program. If you think an additional comment or particular organization will get your ideas across more effectively, do it. However, if you are considering deviating significantly from the guidelines or if you are in doubt about something, please discuss it with us first.