Java Reference
In-Depth Information
balance = balance + amount;
7. What is the value of n after the following sequence of statements?
n--;
n++;
n--;
P RODUCTIVITY H INT 4.1: Avoid Unstable Layout
Arrange program code and comments so that the program is easy to read. For
example, do not cram all statements on a single line, and make sure that braces { }
line up.
However, be careful when you embark on beautification efforts. Some
programmers like to line up the = signs in a series of assignments, like this:
nickels = 0;
dimes = 0;
quarters = 0;
This looks very neat, but the layout is not stable. Suppose you add a line like the
one at the bottom of this:
nickels = 0;
dimes = 0;
quarters = 0;
halfDollars = 0;
Oops, now the = signs no longer line up, and you have the extra work of lining
them up again.
Here is another example. Some programmers like to put a column of asterisks (*)
in documentation comments, like this:
/**
* Computes the change due and resets the cash
register for the
* next customer.
* @return the change due to the customer
*/
It looks pretty, but it is tedious to rearrange the asterisks when editing comments.
Search WWH ::




Custom Search