• Post Reply Bookmark Topic Watch Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:



 
This is my favorite show. And this is my favorite tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!