

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


File Headers
The following should appear at the top of each source file:
//
// CS414, Assignment #x //
/* This should be a comment describing the contents of the file. List all of the classes by access specifier as follows:
Public Classes: Class1 - a brief description Class2 - a brief description Class3 - a brief description
Protected Classes: None.
Private Classes: AprivateClass - a brief description */
If you use a version control system that inserts revision comments directly into your file (a good idea!), have them inserted at the end of the file after the source code. The rationale for this is that the clarity and readability of the program are just as important as the semantics that it embodies. Placing revision comments near the top of the file only makes it more difficult to find things. Each time a revision is made, a new set of comments (presumably) are added which pushes everything that follows further down, breaking whatever conceptual integrity the reader has about the file. What is important is that the comments be present in the file, assessable if needed. Placing them at the end achieves this and makes the file easier to read.
Block Style
Use the following style of indentation and brace alignment (indentation levels should be four spaces): Please do not use tabs.
class SomeClass { int fSomeStateVariable = 0; // Invariant( fSomeState >= 0 && fSomeState < 10 )
public void foo() {
// Method description: This method… // Require( conditions that must be true to call method ) // Ensure( conditions that must be true after method has // executed)
int i;
for ( i = 0; i < 10; ++i ) { System.out.println( “Line “ + i );
if ( i % 2 == 0 ) { // Print a blank line. System.out.println( “” ); } } } // public void foo()
} // class SomeClass
In general, both opening and closing braces should line up with the first character of the keyword (e.g. if, while, for, etc.) that they correspond to. Statements within the block should be indented four spaces.
Note the comments on the closing braces of the class specification and the function definition. These are particularly important as an aid to finding things in the file and for maintaining one's orientation. The commenting convention includes the complete signature for the class and the function. This crucial for distinguishing overloaded method names.
Variables
Methods