This page was migrated from a javaranch.com.jsp
Java Programming Style Guide
3 - Coding
3.1 - Constructs to Never Use
<strong>Never Use do..while</strong>
<em>Reasoning: Consider that the programmer looking at your code is probably examining
each method starting at the top and working down. When encountering a loop, the first
thing the programmer wants to know is what terminates the loop. If you have that logic at
the bottom, it is harder to read. Further, many less experienced programmers are not
familiar with do..while, but may be required to modify your code.</em>
So rather than:
<strong>Never Use "return" in the Middle of a Method</strong>
<em>Reasoning: Using "return" in the middle of a method makes it difficult to
later break the method into smaller methods. It also forces the developer to consider more
than one exit point to a method. </em>
<strong>Never Use "continue"</strong>
<em>Reasoning: Using "continue" makes it difficult to later break the
construct into smaller constructs or methods. It also forces the developer to consider
more than one end point for a construct. </em>
<strong>Never Use "break" Other Than in a Switch Statement</strong>
<em>Reasoning: Using "break", other than for switch statement control, makes
it difficult to later break a construct into smaller constructs or methods. It also forces
the developer to consider more than one end point for a construct. </em>
3.2 - Do Not Compound Increment or Decrement Operators
Use an extra line for the increment or decrement.
Examples:
3.3 - Initialization
Try to not declare a variable until just before it is used unless it will impact the
performance of the code.
Examples: