Style Guide for CS 159

This Style Guide should be used as a reference for all work turned in for credit, both labs and programming assignments.  It is based on (but not identical to) standard java coding guidelines including the Sun Java Coding Conventions and the Code Style Guidelines for Android.

Names

All names should be descriptive and readable: subTotal rather than s; grade rather than grd.  Multiple word names should use a capital letter to separate words (e.g. subTotal). Variable names should balance clarity with brevity. The name person is better than currentPersonObject. However, per is worse than either (percentage? person? permitted?).

Declarations

Where and when to declare variables.

Indentation

Indentation provides a visual structure for your program.

Operators

Structure

Structure provides readability.

Comments

The point of comments is to clarify code that might otherwise be difficult for the reader to follow. Well organized Java code with informative variable names should require few comments inside of method bodies.

Documentation

Every class must include a Javadoc comment like the following.

       /**
	* Overall description of the class goes here
        *
	* @author Your name goes here
	* @version Vn -date (date may be in MM/DD/YY or MM/YY format)
	*/
    

All methods must contain a Javadoc comment preceding the method header as shown in the example below.   The description should describe the "black box" behavior of the method (what it does).  If there are parameters, then there must be one @param tag for each parameter in the format shown below.  If there is a return value, there must be one @return tag which describes the return value (not the variable name).  Finally, if the method throws one or more exceptions, @throws tags must be used to describe the circumstances under which each exception will be thrown.

      /**
      * Overall description (black box behavior) of the method goes here.
      *
      * @param parameterName Describe each input parameter. You must have one
      * @param line for each parameter
      * @return Describe the value that this method returns.
      * @throws ExceptionName Describe under what conditions the exception may 
      * be thrown
      */
      

Acknowledgments

Every programming assignment must contain the following section which follows the class description or must cite any sources used (such as a TA).  You should either include this statement in all files or minimally it may appear in the file containing your main method.

       /*
	* References and Acknowledgments: I received no outside help with this
	* programming assignment.
	*/

OR

       /*
	* References and Acknowledgments: TA Glenn helped me with the 
	* foo method.
	*/
    
This acknowledgment is not necessary for lab assignments. Note the single star after the slash; this is not a Javadoc comment.

Miscellaneous