General
Every programming department has some set of standards or conventions that programmers are expected to follow. The purpose of these standards is make programs readable and maintainable. After all, you may be the programmer who maintains your own code more than six months after having written the original. While no two programming departments' standards/conventions may be the same, it is important that all members of the department follow the same standards. Neatness counts!!!In general we will follow the Code Conventions for the Java Programming Language as developed by the Sun Developer Network. It is your responsibility to read, understand, and use these standards. In particular, graders will be looking for you to adhere to standards regarding
Comments are meant to help the reader of a program. They do not help by saying things that the code already plainly says, or by contradicting the code, or by distracting from the code with elaborate typographical displays. The best comments aid the understanding of a program by briefly pointing out salient details or by providing a larger-scale view of the proceedings".
Names
.java
file
extension.
private
.
Comments
Every .java file should contain an opening "file header comment" describing the class within the file and containing other pertinent information. This comment must be a block comment that begins with /** and include the following information./** * File: Table.java * Project: CMSC 202 Project 3, Fall 2005 * @author Bob Smith * Date: 9/22/05 * Section: 0304 * E-mail: bsmith22@gl.umbc.edu * Class Invariant * 1. number of legs is either 3 or 4 * 2. shape is one of ROUND, RECTANGLE or OVAL */
Method Comments
Method comments are the primary form of documentation for the user of our class methods. It is important that this documentation be both complete and accurate as it forms a "contract" between the class user and and the class implementer. These comments are sometimes refered to either "documentation comments" or "interface comments".Each class method must have a comment that includes the following information.
A post-condition is a statement describing what will be true when the function call is completed (assuming the pre-condition is met and the function completes; see text page 207).
For example, a method that calculates the area of a Circle might have a header like this
/** * Name: CircleArea * PreCondition: the radius is greater than zero * PostCondition: Returns the calculated area of the circle * @params radius - the radius of the circle */ double CircleArea ( double radius ) { // handle unmet precondition if (radius < 0.0) return 0.0; else return Math.PI * radius * radius; }