CPSC 120 Java Style Guide

Spring 1998

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. The CPSC 120 graders will expect your Java assignments to conform to these style and documentation conventions.

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. Include a header comment at the top of each class and method

3. Write self-documenting code.

4. Follow standard formatting conventions.

5. Use inline comments sparingly but whenever necessary.

6. Present your test cases clearly and methodically.

Many of the CPSC 120 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.

7. Use common sense.

Remember that the CPSC 120 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.

This style guide was adapted from one prepared by Prof. Ken Goldman at Washington Univ. at St. Louis.