About the Principles found in Java Elements

Java Elements features a number of programming principles not openly advocated in other introductory texts. Java Elements presents the reasoning behind rules-of-thumb that help designers of programs make the best design decisions possible. Here are a few of the principles:

A useful principle is not fact, but a guide.

Use comments to make your programs readable.

Experiment.

Spell out and capitalize words in identifiers.

Initialize variables before they are used.

Use parentheses to make explicit the order of evaluation.

Later drawing usually obscures earlier work.

Program with a reader in mind.

Inverting a drawing an even number of times makes it disappear.

Use the while loop to do something zero or more times.

Use the do-while loop to do something at least once.

The for loop is best used when counting or iterating a specific number of times.

The structure of the program should model the structure of the problem

Pre- and postconditions provide an easy method for formalizing your documentation.

Functions don't generate output.

Return a result on the last line of a function.

Seek symmetry in design.

Recursive methods perform tests to identify one or more simple base cases. In other cases progress is made toward the solution using recursion to solve a simpler problem.

Declare instance variables of classes private.

The base case of a recursive class should, itself, be an instance of the class.

Implement recursive structures using recursive methods.

Define the equals method for objects stored in container classes.