At 10:00 AM on May 19, 2006, Jean-Marie Dautelle DeveloperZone Top 100 Send Private message to this user  wrote:
In this "Tips and Tricks", I would like to discuss an addendum to Sun(tm) coding standard to accelerate code development when using modern tools with auto-completion capabilities (e.g. NetBeans, Eclipse ...).


Addendum to Sun(tm) Coding Standard - http://java.sun.com/docs/codeconv/ 


9. Naming Convention:


   - All non-constant variables members start with underscore.

   
     class Foo {
     	int _value;
     	int _isReady;
     }

     

     Rationale: Facilitates auto-completion (typing '_' shows class members only).

   

   - The first letter after the underscore is uppercase for static variables.

   

   
     class Foo {
     	static boolean _IsInitialized;
     	static FastTable<Foo> _Instances;
     }

   

     

     Rationale: Distinguishes static and non-static class variables.

   

   - Variable name for arrays or collections are plural.

        

   
     class Foo {
     	static Factory[] _Factories; // NOT: _FactoryArray
     	FastList<Foo> _children; // NOT: _childList
     }

   

     

     Rationale: Improves abstraction (and readability).


 - Acronyms -  Capitalize all letters except for leading acronyms of variable names (all lower case).

     
     XMLStreamWriter createXMLStreamWriter();
     UTF8Stream utf8Stream;


   

     Rationale: Consistent with Standard Java Library (JDK).

     

10. Programming Practices:


   - Class prefixes for static method invocations (e.g. Factory.newId()).

   

     Rationale: Emphasizes that the method is static.

      

   - Consistent naming for factory methods: "valueOf", "newInstance" 

     or "getInstance".

   

     Rationale: Facilitates search (consistency).


   - null arguments are disallowed unless explicitly authorized:

   

   
     /**
      * ...
      * 
      * @param obj the object to search for or <code>null</code>. 
      */

   


     Rationale: Reduces ambiguity (and comments).


   

   - If/else block statements enclosed with braces except for escape statements:

     

   
         if (!precondition)                if (obj == null) 
             throw new Exception();            return null;
         doSomething();                    doSomething();

   

         

     Rationale: Increases readability (reduces code).



12. Others references. 


    Java Programming Style Guidelines 

         - http://geosoft.no/development/javastyle.html

29 replies so far 
