Your program is easier to read, debug and understand when you:
* Use comments
- a block of comments at the beginning of the program
that gives
your name, course number and section,
instructor's name, purpose
of the program, limitations, etc.
- a block of comments at the beginning of each major
section of the
program that explains what that section
does.
* Choose identifiers appropriately
- identifiers for variables and methods should start
with a lower
case letter and use an upper case letter
when words are run
together
- identifiers for classes should start with an upper
case letter
and use an upper case letter when words
are run together
- identifiers for constants should be all upper
case
- a variable name should indicate the value that
it holds;
eg, depositAmount, age, homeAddress,
...
- a method name should be a verb phrase indicating
the action that
it performs; eg, displayResults, calculateGPA,
...
* Use indentation. Statements within a block should be aligned and
nested blocks should be further indented. For example,
{
statement;
statement;
{
statement;
statement;
statement;
}
statement;
}
Nested blocks become important in Chapter
5.
Use the sample programs that are in the book and those that are in
the lecture notes as examples.