Java Reference
In-Depth Information
}
This scheme makes it easy to spot matching braces.
Some programmers put the opening brace on the same line as the if :
if (amount <= balance) {
double newBalance = balance - amount;
balance = newBalance;
}
185
186
This saves a line of code, but it makes it harder to match the braces.
It is important that you pick a layout scheme and stick with it. Which scheme you
choose may depend on your personal preference or a coding style guide that you
must follow.
P RODUCTIVITY H INT 5.1: Indentation and Tabs
When writing Java programs, use indentation to indicate nesting levels:
public class BankAccount
{
| . . .
| public void withdraw(double amount)
| {
| | if (amount <= balance)
| | {
| | | double newBalance = balance -
amount;
| | | balance = newBalance;
| | }
| }
| . . .
}
0123
Indentation level
How many spaces should you use per indentation level? Some programmers use
eight spaces per level, but that isn't a good choice:
public class BankAccount
{
Search WWH ::




Custom Search