| I l @ ve RuBoard |
3.3 Naming Style
Many
One additional note on variable names:
Also, I work for a company which has people from 62 different
Which naming convention you use is up to you. It is more a matter of religion than of style. However, using a consistent naming style is extremely important. In this book we have
|
| I l @ ve RuBoard |
| I l @ ve RuBoard |
3.4 Coding Religion
Computer scientists have devised many programming styles. These include structured programming, top-down programming, and
goto
-less programming. Each of these styles has its own following or cult. I use the
The rules presented in this book are the result of
|
| I l @ ve RuBoard |
| I l @ ve RuBoard |
3.5 Indentation and Code Format
To make programs easier to understand, most programmers indent their programs. The general rule for a C++ program is to indent one level for each new block or conditional. In Example 3-1 there are three levels of logic, each with its own indentation level. The
while
statement is outermost. The statements inside the
while
are at the
There are two styles of indentation, and a vast religious war is being waged in the programming community as to which is better. The first is the short form:
while (! done) {
std::cout << "Processing\n";
next_entry( );
}
if (total <= 0) {
std::cout << "You owe nothing\n";
total = 0;
} else {
std::cout << "You owe " << total << " dollars\n";
all_totals = all_totals + total;
}
In this case, most of the curly braces are put on the same line as the statements. The other style puts the curly braces on lines by
while (! done) {
std::cout << "Processing\n";
next_entry( );
}
if (total <= 0) {
std::cout << "You owe nothing\n";
total = 0;
} else {
std::cout << "You owe " << total << " dollars\n";
all_totals = all_totals + total;
}
Both formats are commonly used. You should use the format you feel most comfortable with. This book uses the short form. (It saves paper.)
The amount of indentation is left to the programmer. Two, four, and eight spaces are common. Studies have shown that a four-space indent makes the most readable code. You can choose any indent
|
| I l @ ve RuBoard |