A Guide to Program Preparation and Grading

This document is intended as a guide for CMP 12A students and readers. It is modified from earlier guidelines for this class.


Pair Programming:

Working Together:

The graded programming homeworks are to be done in two person teams. You may freely give and receive help with the computer facilities, editors, UNIX, debugging techniques, the meaning and proper use of Java constructs, etc.. You should not discuss the graded programming homeworks with students other than your teammate until after they are turned in. In particular you should not view another person/teams program, or allow someone to view any part of your program, prior to turning it in. Obviously, copying any part of another person/team's program, or allowing your program to be copied is not permitted. A program will be in use to detect copying. If you have any questions on this important point, please see me.

What is Pair programming:

"Pair programming is a practice in which two programmers work side-by-side at one computer, continuously collaborating on the same design, algorithm, code, or test. This method has been demonstrated to improve productivity and the quality of software products." Williams, Laurie and Kessler, Robert R., All I Really Need to Know about Pair Programming I Learned In Kindergarten, Communications of the ACM, May 2000. For additional reading on pair programming click here. For how we use pair programming in this class, click here.

Grading Guide:

Log file:

All programs must be done with your partner. For each assignment, you must include an electronic log indicating your perceived contributions.

7 point scale for grading programmings:


7(Makes you weep at its beauty): Not possible for pgm1.

6(Extra features or particularly elegant): 
  Possibilities include support for user input of multiple data sets,
  and testing for proper input (e.g. you can't have a negative number
  of quarters).
  To be done properly these require language constructs not yet covered
  in class.

5(Satisfies all requirments - a job well done):
  5.1 Syntactically correct - it compiles cleanly
  5.2 Proper comments including name, date, assignment number and
      program description in opening comment, and at least one useful
      inline comment.
  5.3 Proper and consistent indenting.
  5.4 Descriptive variable names (e.g. numQuarters not q or x for the
      number of quarters entered by the user).
  5.5 Correct output.
  5.6 Descriptive, well formatted output.

4(Meets general requirements with a few minor problems):
  Lacking one or two of 5.2-5.4, 5.6.

3(Serious problems):
  Lacking more than two of 5.2-5.4, 5.6, or
  lacking 5.5.

2(Extremely serious problems but demonstrates some effort and understanding):
  Lacking 5.1.

1(Shows little effort and does not represent passing work):



Details:

Clean compilation

A program that runs and does only part of the assignment is better than one that is supposed to do it all, but doesn't run. Build your program up in stages: start with just a little and get it running, then add more features and get them working, and so on. Make sure you turn in something that runs. If the program does not compile successfully, it cannot get higher than a 2 out of 7.

Code structure and Readability

This area is important. Use top-down programming techniques; construct the program as a small main program and a collection of methods. Each method should do a well-defined job and be small enough to fit on a workstation screen (as a rule of thumb). The division should be done so that the pieces share a minimum amount of information. Information that must be shared should be passed as parameters whenever possible; the use of global variables must be kept to an absolute minimum. Good structure also means using the right Java construct for each job, e.g. using a while rather than a for loop, or a constant instead of a variable, as appropriate.

Naming: Use descriptive names for variables, methods, etc., for example ReverseString, NumOfStudents. Short or single-letter names are acceptable if they are used in a small part of the code and their meanings are clear; for example, i and j (lower case) are conventionally used for loop counters and array indices. It is suggested that you capitalize names according to the formatting guidelines outlined below. However, you may use another scheme if it is well thought out. Be consistent.

Avoid use of magic numbers in your program.

Documentation: A program should be properly formatted and commented. It should begin with a header comment called the preamble. The preamble should contain the following information:

The preamble should be enclosed in a box to make it stand out from the rest of the program. For example:


/*********************************************************************/
/* Program: PreserveFreeSpeech                                       */
/* Authors: Judge Judy (judgejudy@cats)                              */
/*          Judge Hatchett (judgehatchett@cats)                      */
/*          Judge Joe Brown (judgejoebrown@cats)                     */
/*          Judge Mathis (judgemathis@cats)                          */
/*                                                                   */
/* CMP 12A, Fall 2003                                                */
/* Programming Assignment #1                                         */
/* September 29, 2003                                                */
/*                                                                   */
/* This programs figures out whether telemarketers, politicians and  */
/* non profit organizations have the "free speech" right to enter    */
/* anyone's home through the phone line.                             */
/*                                                                   */
/* Input:                                                            */
/* Lawyers arguments, constitutional laws, polls, etc.               */
/*                                                                   */
/* Output:                                                           */
/* Development of tecnology to block junk calls, or a national       */
/* do-not-spam list.                                                 */
/*                                                                   */
/* Bugs and limitations:                                             */
/* Success rate is 99.99% unless someone really blew it.             */
/*********************************************************************/

A similar, although simpler, comment block should precede each method. It should give the name of the method and its purpose, and describe all information passed into and out of the method, and the meaning of each item. Note that the comment box also makes it easier to see the scope of each method. See example below.


/*********************************************************************/
/* DrawRectangle( Point corner1, Point corner2 )                     */
/*                                                                   */
/* Draws a rectangle in the current color using the 2 points as      */
/* diagonally opposite points.                                       */
/*                                                                   */
/* Input:  2 diagonally opposite points.                             */
/* Output: Really nice looking rectangle.                            */
/*********************************************************************/

Use in-line comments to describe the purpose and operation of sections of code. These should be at a high semantic level, e.g.


/*  Find the largest element in the array.  */

Generally, you will include one comment in the program body for each major algorithm step. A comment within the program body should describe what the step does rather than simply restate the step in English. In addition, on each line whose purpose is not intuitively obvious, use a short comment to tell someone reading the program what is going on. For example:


/*  Find the minimum of FirstNum and SecondNum  */
min = (FirstNum + SecondNum - abs(FirstNum - SecondNum))/2;

rather than


/*
*  Add FirstNum to SecondNum, subtract the absolute value
*  of their difference and divide that value by 2.
*/

Use comments to state assertions that you expect to be true at a particular point in the program. This makes the program easier to understand and debug. For example, the following assertion might be placed right after a loop.
/*  Here Max contains the largest element of the array  */


Formatting Guide:

Order

The text of a program should be arranged in a way that suggests its structure, in order to make it as clear and readable as possible. Make sure all lines are 80 characters or less. That is, use carriage returns! Sometimes they wrap around on the terminal and look right, but get cut off when the program is printed or turned in.

Capitalization

Classes typically start with a capital letter, while methods and variables typically start with a lower case letters. If the class, method, or variable names consist of two or more words, capitalize the first letter of each word. Examples: class ForgetCampaignPromises; method buyVotes; variable howMuch. We recommend that you follow this convention in your programs to improve its readability.

Indentation

Vertically align constructs to show where they pair up. For example: scoping {...}, if ... else, switch, while. Use spaces to indent, not tabs, because tabs are handled differently by different output devices. A program indented with tabs that looks fine on a terminal may come out very strange when printed. Single-line and block comments should be indented to match the thing they refer to.

Blank lines

Blank lines should appear before and after comment blocks, and may be used to break a program into logical sections. Avoid using too many blank lines, because they waste screen space and make the code look chopped up. Use more than one only for very significant breaks in large programs.

Lists

Long lists of declarations, method parameters, and enumerated type names may be arranged vertically, indented one step from the line that begins the list. Do this if the list items would be hard to read if jumbled together, or if explanatory comments follow each item. For example:


int PlayVideoClip(
    int     CompressionMethod,    //  mpeg, quicktime,..
    int     PlaySpeed,            //  slow-mo, fast-fo
    int     Volume,               //  0..9
    movie_t VideoClip)

Last modified Monday, 20-Oct-2003 12:30:10 PDT.