Programming Assignment 2 - Object Oriented Programming Languages | CS 535, Assignments of Computer Science

Material Type: Assignment; Professor: Whitney; Subject: Computer Science; University: San Diego State University; Term: Fall 2000;

Typology: Assignments

Pre 2010

Uploaded on 03/28/2010

koofers-user-bdo
koofers-user-bdo 🇺🇸

10 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
10/9/00 Doc 11 Assignment 2 Comments, Slide # 1
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,
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Programming Assignment 2 - Object Oriented Programming Languages | CS 535 and more Assignments Computer Science in PDF only on Docsity!

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

  • Use styles that are easy to maintain
  • module: Print *
  • author: Roger Whitney *
  • date: Sept. 10, 1995 *
  • blah blah blah *

***********************************/

module: Print

author: Roger Whitney date: Sept. 10, 1995

blah blah blah

***********************************/

  • Comment as you go along

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

  • Repeat of the code

X := X + 1 /* add one to X

/* if allocation flag is zero */

if ( AllocFlag == 0 ) ...

  • Explanation of how code works

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;

  • Marker in the code

/* **** Need to add error checking here **** */

  • Summary of the code

Distills a few lines of code into one or two sentences

  • Description of the code's intent

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