









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Professor: Whitney; Subject: Computer Science; University: San Diego State University; Term: Fall 2000;
Typology: Assignments
1 / 15
This page cannot be seen from the preview
Don't miss anything!










CS 535 Object-Oriented Programming & Design Fall Semester, 2000 Doc 11 Assignment 2 Comments Contents Indentation, White space .............................................................. 2 Names .......................................................................................... 3 Comments .................................................................................... 6 Commenting Efficiently............................................................... 7 Kinds of Comments .................................................................. 10 Keep Code simple ...................................................................... 12 Asserts........................................................................................ 13 Testing ........................................................................................ 13 Try-catch..................................................................................... 14 Points & Rectangles ................................................................... 15
References
Student papers
Code Complete , Steve McConnell, Microsoft Press, 1993,
Assignment 2 Comments Indentation, White space
Use white space to make program readable
Use indentation to show the program structure
One space indentation is not enough
public Point getCenter() { return lowerLeft.add( upperRight).divide( 2); }
public Point getCenter() { return lowerLeft.add( upperRight).divide( 2); }
public Point getCenter() { return lowerLeft.add( upperRight).divide( 2); }
public Point getCenter(){ return lowerLeft.add( upperRight).divide( 2); }
public Point getCenter() { return lowerLeft.add( upperRight).divide( 2); }
Make sure name matches the usage
Some assignments used the name upperLeft but meant lowerLeft
Java Standards
thisIsTheJavaWayForMethodsAndVaraibles
ClassName
this_is_not_the_java_way
use equals() not identical() for a test of equality
public class Rectangle { public boolean containsRectangle( Rectangle ) { blah} public boolean containsPoint( Point ) {blah} }
public class Rectangle { public boolean contains( Rectangle ) { blah} public boolean contains( Point ) {blah} }
Set & Get
public class Rectangle { public void setOrigin( Point origin ) {blah} public Point getPointOrigin( ) {blah} }
public class Rectangle { public void origin( Point origin ) {blah} public Point origin( ) {blah} }
The Java Standard
public class Rectangle { public void setOrigin( Point origin ) {blah} public Point getOrigin( ) {blah} }
Commenting Efficiently
***********************************/
module: Print
author: Roger Whitney date: Sept. 10, 1995
blah blah blah
***********************************/
What does this do?
for i := 1 to Num do MeetsCriteria[ i ] := True; for i := 1 to Num / 2 do begin j := i + i; while ( j <= Num ) do begin MeetsCriteria[ j ] := False; j := j + i; end; for i := 1 to Mun do if MeetsCriteria[ i ] then writeln( i, ' meets criteria ' );
Kinds of Comments
X := X + 1 /* add one to X
/* if allocation flag is zero */
if ( AllocFlag == 0 ) ...
Used to explain complicated or tricky code
p++->c = a
/* first we need to increase p by one, then ..
Make code simpler before commenting
((p++))->c = a
ObjectPointerPointer++; ObjectPointer = ObjectPointerPointer; ObjectPointer ->DataMemberPointer = a;
/* **** Need to add error checking here **** */
Distills a few lines of code into one or two sentences
Explains the purpose of a section of code
/*get current employee information */ intent
/* update EmpRec structure */ what
Asserts
assert( a == true )
verses
assert( a )
assert( a == false )
verses
assert( !a )
Testing
public class Rectangle { public boolean contains( Point origin ) { return true; } }
The above passes most of your tests for contains
Should use a point: Inside Outside On border
Try-catch
try { blah } catch (Exception error) { System.out.println(" There was an error "); System.exit( 0 ); }
The above is almost always the wrong thing to do
The above should not be used in libraries