Java Reference
In-Depth Information
Which brace style is best?
Two major brace styles are commonly used. This one
if (condition) {
// do something
}
values screen real estate more than clarity. This one
if (condition)
{
// do something
}
values clarity over real estate. If we choose to adopt a standard that mandates
the use of braces after conditionals, then the first style is usually sufficient,
because it lets us have more lines of code on the screen at any given time. The
most important thing is to pick a standard and stick with it.
Another consideration is indentation clues. It's important to be able to tell
at a glance which braces belong together. Almost all coding standards use
indentation as one clue. Commenting can be an additional clue, and may or
may not be supported by a standard:
if(i>10){
while(j==4) {
// do something
} // end while
} // end if
Because a good code editor will find matching parentheses, some programmers
might think commenting is unnecessary or even distracting. In any case, code
that has too many consecutive closes to be clear may benefit from refactoring.
9.2.4
Comments
Comments are meant to improve the readability of code for humans. The
examples in this topic are far from sterling examples for commenting, because
the goals of documenting code for a book are far different from the goals of
documenting for a production application. In a book, page space is at a pre-
mium, and we have other means of describing and annotating. A good rule of
thumb is that comments should describe why something is being done, rather
than what is being done. For production applications, we can use comments
to document bugs and obscurities. Comments can clarify and mark.
Java supports three different types of commenting. Block, or C-style
comments, are bracketed with / * and * / characters. Documentation com-
ments, usually used at the top of type definitions and member functions, are
Search WWH ::




Custom Search